Index: lemon/lemon_writer.h
===================================================================
--- lemon/lemon_writer.h	(revision 1435)
+++ lemon/lemon_writer.h	(revision 1476)
@@ -37,6 +37,35 @@
 #include <lemon/maps.h>
 
+#include <lemon/concept_check.h>
+#include <lemon/concept/maps.h>
+
 
 namespace lemon {
+
+  namespace _writer_bits {
+    
+    template <typename Item>
+    class ItemIdWriter {
+    public:
+
+      bool isIdWriter() { return true; }
+
+      void writeId(std::ostream&, const Item&) {}
+      
+      template <class _ItemIdWriter>
+      struct Constraints {
+	void constraints() {
+	  const Item item;
+	  bool b = writer.isIdWriter();
+	  ignore_unused_variable_warning(b);
+	  writer.writeId(os, item);
+	}
+	_ItemIdWriter& writer;
+	std::ostream& os;
+      };
+
+    };
+
+  }
 
   /// \ingroup io_group
@@ -230,4 +259,5 @@
       typedef _Item Item;
       virtual void write(std::ostream&, const Item&) const = 0;
+      virtual bool isIdWriter() const = 0;
     };
 
@@ -245,4 +275,8 @@
       virtual void write(std::ostream& os, const Item& item) const {
 	idWriter.writeId(os, item);
+      }
+
+      virtual bool isIdWriter() const {
+	return idWriter.isIdWriter();
       }
     };
@@ -319,4 +353,5 @@
     NodeSetWriter& writeNodeMap(std::string name, const Map& map, 
 			    const Writer& writer = Writer()) {
+      checkConcept<concept::WriteMap<Node, typename Map::Value>, Map>();
       writers.push_back(
 	make_pair(name, new MapWriter<Node, Map, Writer>(map, writer)));
@@ -447,6 +482,8 @@
 		  bool _forceIdMap = true)
       : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),
-	graph(_graph), id(_id),
-	nodeIdWriter(new IdWriter<Node, NodeIdWriter>(_nodeIdWriter)) {} 
+	graph(_graph), id(_id) {
+      checkConcept<_writer_bits::ItemIdWriter<Node>, NodeIdWriter>();
+      nodeIdWriter.reset(new IdWriter<Node, NodeIdWriter>(_nodeIdWriter));
+    } 
 
     /// \brief Destructor.
@@ -481,4 +518,5 @@
     EdgeSetWriter& writeEdgeMap(std::string name, const Map& map, 
 			    const Writer& writer = Writer()) {
+      checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>();
       writers.push_back(
 	make_pair(name, new MapWriter<Edge, Map, Writer>(map, writer)));
@@ -499,4 +537,7 @@
     /// Write the content of the section.
     virtual void write(std::ostream& os) {
+      if (!nodeIdWriter->isIdWriter()) {
+	throw DataFormatError("Cannot find nodeset or ID map");
+      }
       for (int i = 0; i < (int)writers.size(); ++i) {
 	if (writers[i].first == "id") {
@@ -622,6 +663,8 @@
 		       bool _forceIdMap = true)
       : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),
-	graph(_graph), id(_id),
-	nodeIdWriter(new IdWriter<Node, NodeIdWriter>(_nodeIdWriter)) {} 
+	graph(_graph), id(_id) {
+      checkConcept<_writer_bits::ItemIdWriter<Node>, NodeIdWriter>();
+      nodeIdWriter.reset(new IdWriter<Node, NodeIdWriter>(_nodeIdWriter));
+    } 
 
     /// \brief Destructor.
@@ -656,4 +699,5 @@
     UndirEdgeSetWriter& writeUndirEdgeMap(std::string name, const Map& map, 
 					  const Writer& writer = Writer()) {
+      checkConcept<concept::WriteMap<UndirEdge, typename Map::Value>, Map>();
       writers.push_back(
 	make_pair(name, new MapWriter<UndirEdge, Map, Writer>(map, writer)));
@@ -666,4 +710,5 @@
     template <typename Map>
     UndirEdgeSetWriter& writeEdgeMap(std::string name, const Map& map) {
+      checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>();
       writeUndirEdgeMap("+" + name, composeMap(forwardMap(graph), map));
       writeUndirEdgeMap("-" + name, composeMap(backwardMap(graph), map));
@@ -677,6 +722,7 @@
     UndirEdgeSetWriter& writeEdgeMap(std::string name, const Map& map, 
 				     const Writer& writer = Writer()) {
+      checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>();
       writeUndirEdge("+" + name, composeMap(forwardMap(graph), map), writer);
-      writeUndirEdge("-" + name, composeMap(forwardMap(graph), map), writer);
+      writeUndirEdge("-" + name, composeMap(backwardMap(graph), map), writer);
       return *this;
     }
@@ -695,4 +741,7 @@
     /// Write the content of the section.
     virtual void write(std::ostream& os) {
+      if (!nodeIdWriter->isIdWriter()) {
+	throw DataFormatError("Cannot find nodeset or ID map");
+      }
       for (int i = 0; i < (int)writers.size(); ++i) {
 	if (writers[i].first == "id") {
@@ -812,6 +861,9 @@
     NodeWriter(LemonWriter& _writer, const _IdWriter& _idWriter, 
 	       const std::string& _id = std::string()) 
-      : Parent(_writer), id(_id), 
-	idWriter(new IdWriter<typename Graph::Node, _IdWriter>(_idWriter)) {} 
+      : Parent(_writer), id(_id) {
+      checkConcept<_writer_bits::ItemIdWriter<Node>, _IdWriter>();
+      idWriter.reset(new IdWriter<Node, _IdWriter>(_idWriter));
+    }
+
 
     /// \brief Destructor.
@@ -847,4 +899,7 @@
     /// Write the content of the section.
     virtual void write(std::ostream& os) {
+      if (!idWriter->isIdWriter()) {
+	throw DataFormatError("Cannot find nodeset or ID map");
+      }
       for (int i = 0; i < (int)writers.size(); ++i) {
 	os << writers[i].first << ' ';
@@ -888,6 +943,8 @@
     EdgeWriter(LemonWriter& _writer, const _IdWriter& _idWriter, 
 	       const std::string& _id = std::string()) 
-      : Parent(_writer), id(_id), 
-	idWriter(new IdWriter<typename Graph::Edge, _IdWriter>(_idWriter)) {} 
+      : Parent(_writer), id(_id) {
+      checkConcept<_writer_bits::ItemIdWriter<Edge>, _IdWriter>();
+      idWriter.reset(new IdWriter<Edge, _IdWriter>(_idWriter));
+    }
 
     /// \brief Destructor.
@@ -922,4 +979,7 @@
     /// Write the content of the section.
     virtual void write(std::ostream& os) {
+      if (!idWriter->isIdWriter()) {
+	throw DataFormatError("Cannot find edgeset or ID map");
+      }
       for (int i = 0; i < (int)writers.size(); ++i) {
 	os << writers[i].first << ' ';
@@ -967,7 +1027,10 @@
     UndirEdgeWriter(LemonWriter& _writer, const _IdWriter& _idWriter, 
 	       const std::string& _id = std::string()) 
-      : Parent(_writer), id(_id), 
-	undirEdgeIdWriter(new IdWriter<UndirEdge, _IdWriter>(_idWriter)),
-	edgeIdWriter(new IdWriter<Edge, _IdWriter>(_idWriter)) {}
+      : Parent(_writer), id(_id) {
+      checkConcept<_writer_bits::ItemIdWriter<Edge>, _IdWriter>();
+      checkConcept<_writer_bits::ItemIdWriter<UndirEdge>, _IdWriter>();
+      undirEdgeIdWriter.reset(new IdWriter<UndirEdge, _IdWriter>(_idWriter));
+      edgeIdWriter.reset(new IdWriter<Edge, _IdWriter>(_idWriter));
+    }
 
     /// \brief Destructor.
@@ -1009,4 +1072,10 @@
     /// Write the content of the section.
     virtual void write(std::ostream& os) {
+      if (!edgeIdWriter->isIdWriter()) {
+	throw DataFormatError("Cannot find undirected edgeset or ID map");
+      }
+      if (!undirEdgeIdWriter->isIdWriter()) {
+	throw DataFormatError("Cannot find undirected edgeset or ID map");
+      }
       for (int i = 0; i < (int)undirEdgeWriters.size(); ++i) {
 	os << undirEdgeWriters[i].first << ' ';
