{"id":125,"date":"2008-11-13T23:56:24","date_gmt":"2008-11-13T14:26:24","guid":{"rendered":"http:\/\/www.clearchain.com\/blog\/?p=125"},"modified":"2010-06-23T15:32:23","modified_gmt":"2010-06-23T06:02:23","slug":"stlset","status":"publish","type":"post","link":"https:\/\/www.clearchain.com\/blog\/posts\/stlset","title":{"rendered":"stl::set"},"content":{"rendered":"<p>Working with Mark&#8217;s dnl code, we came across an interesting issue. Mark had used the stl::set class for some of his code and whilst it compiled fine under Visual Studio, it failed to compile under gcc\/g++. With the error:<\/p>\n<pre>dnlCommon\/Logger.cpp: In member function 'void dnlCommon::Logger::setMask(std::ostream&amp;, std::bitset&lt;5ul&gt;)':\r\ndnlCommon\/Logger.cpp:64: error: invalid initialization of reference of type 'dnlCommon::Logger::LoggerPair&amp;' from expression of type 'const dnlCommon::Logger::LoggerPair'\r\n\/usr\/local\/lib\/gcc-4.0.4\/include\/c++\/bits\/stl_algo.h: In function '_OutputIterator std::remove_copy(_InputIterator, _InputIterator, _OutputIterator, const _Tp&amp;) [with _InputIterator = std::_Rb_tree_const_iterator&lt;dnlCommon::Logger::LoggerPair&gt;, _OutputIterator = std::_Rb_tree_const_iterator&lt;dnlCommon::Logger::LoggerPair&gt;, _Tp = dnlCommon::Logger::LoggerPair]':\r\n\/usr\/local\/lib\/gcc-4.0.4\/include\/c++\/bits\/stl_algo.h:1112:   instantiated from '_ForwardIterator std::remove(_ForwardIterator, _ForwardIterator, const _Tp&amp;) [with _ForwardIterator = std::_Rb_tree_const_iterator&lt;dnlCommon::Logger::LoggerPair&gt;, _Tp = dnlCommon::Logger::LoggerPair]'\r\ndnlCommon\/Logger.cpp:54:   instantiated from here\r\n\/usr\/local\/lib\/gcc-4.0.4\/include\/c++\/bits\/stl_algo.h:1037: error: passing 'const dnlCommon::Logger::LoggerPair' as 'this' argument of 'dnlCommon::Logger::LoggerPair&amp; dnlCommon::Logger::LoggerPair::operator=(const dnlCommon::Logger::LoggerPair&amp;)' discards qualifiers<\/pre>\n<p>It turned out that the issue occurred with the assignment operator (operator = ) on the <code>stl::set<\/code> class. Tracing the problem we found that <code>set&lt;TYPE&gt;::iterator<\/code> is <code>const<\/code> rather than non cost. Hence calling stl functions that made use of the iterators but also the assignment operator would fail.<\/p>\n<p>Looking further into the problem I found:<\/p>\n<pre>      \/\/ _GLIBCXX_RESOLVE_LIB_DEFECTS\r\n      \/\/ DR 103. set::iterator is required to be modifiable,\r\n      \/\/ but this allows modification of keys.\r\n      typedef typename _Rep_type::const_iterator iterator;\r\n      typedef typename _Rep_type::const_iterator const_iterator;<\/pre>\n<p>Hmm, that&#8217;s strange. A bit of <a class=\"external text\" title=\"http:\/\/google.com\" rel=\"nofollow\" href=\"http:\/\/google.com\/\">googling<\/a> revieled the problem to be an issue with the stl standard. Fixes to gcc\/g++ are listed at <a class=\"external free\" title=\"http:\/\/gcc.gnu.org\/onlinedocs\/libstdc++\/ext\/howto.html\" rel=\"nofollow\" href=\"http:\/\/gcc.gnu.org\/onlinedocs\/libstdc++\/faq.html\">http:\/\/gcc.gnu.org\/onlinedocs\/libstdc++\/ext\/howto.html<\/a> in particular error 103 is listed at <a class=\"external free\" title=\"http:\/\/gcc.gnu.org\/onlinedocs\/libstdc++\/ext\/lwg-defects.html#103\" rel=\"nofollow\" href=\"http:\/\/gcc.gnu.org\/onlinedocs\/libstdc++\/ext\/lwg-defects.html#103\">http:\/\/gcc.gnu.org\/onlinedocs\/libstdc++\/ext\/lwg-defects.html#103<\/a><br \/>\nSo it looks like the bug was ratified by the C++ committee in 1998 and it still isn&#8217;t fixed in Visual Studio 2005 (VC++ 8.0)\u00a0!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Working with Mark&#8217;s dnl code, we came across an interesting issue. Mark had used the stl::set class for some of his code and whilst it compiled fine under Visual Studio, it failed to compile under gcc\/g++. With the error: dnlCommon\/Logger.cpp: In member function &#8216;void dnlCommon::Logger::setMask(std::ostream&amp;, std::bitset&lt;5ul&gt;)&#8217;: dnlCommon\/Logger.cpp:64: error: invalid initialization of reference of type &#8216;dnlCommon::Logger::LoggerPair&amp;&#8217;<a href=\"https:\/\/www.clearchain.com\/blog\/posts\/stlset\"> <font size=-2>[..more..]<\/font><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[99,98],"class_list":["post-125","post","type-post","status-publish","format-standard","hentry","category-programming","tag-iterator","tag-stl"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>stl::set - ClearChain<\/title>\n<meta name=\"description\" content=\"Working with Mark&#039;s dnl code, we came across an interesting issue. Mark had used the stl::set class for some of his code and whilst it compiled fine under\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.clearchain.com\/blog\/posts\/stlset\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin Close\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/stlset#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/stlset\"},\"author\":{\"name\":\"Benjamin Close\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/aef6faa2c32188398139db9270ca1c98\"},\"headline\":\"stl::set\",\"datePublished\":\"2008-11-13T14:26:24+00:00\",\"dateModified\":\"2010-06-23T06:02:23+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/stlset\"},\"wordCount\":167,\"commentCount\":3,\"keywords\":[\"iterator\",\"stl\"],\"articleSection\":[\"Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.clearchain.com\/blog\/posts\/stlset#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/stlset\",\"url\":\"https:\/\/www.clearchain.com\/blog\/posts\/stlset\",\"name\":\"stl::set - ClearChain\",\"isPartOf\":{\"@id\":\"https:\/\/www.clearchain.com\/blog\/#website\"},\"datePublished\":\"2008-11-13T14:26:24+00:00\",\"dateModified\":\"2010-06-23T06:02:23+00:00\",\"author\":{\"@id\":\"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/aef6faa2c32188398139db9270ca1c98\"},\"description\":\"Working with Mark's dnl code, we came across an interesting issue. Mark had used the stl::set class for some of his code and whilst it compiled fine under\",\"breadcrumb\":{\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/stlset#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.clearchain.com\/blog\/posts\/stlset\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/posts\/stlset#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.clearchain.com\/blog\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"stl::set\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/#website\",\"url\":\"https:\/\/www.clearchain.com\/blog\/\",\"name\":\"ClearChain\",\"description\":\"-= Daily Happenings =-\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.clearchain.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/aef6faa2c32188398139db9270ca1c98\",\"name\":\"Benjamin Close\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/19dca0aa372edfa901b93c556dfda2e78ad4434558fe4d139598e086315d714a?s=96&d=mm&r=pg\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/19dca0aa372edfa901b93c556dfda2e78ad4434558fe4d139598e086315d714a?s=96&d=mm&r=pg\",\"caption\":\"Benjamin Close\"},\"sameAs\":[\"http:\/\/www.clearchain.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"stl::set - ClearChain","description":"Working with Mark's dnl code, we came across an interesting issue. Mark had used the stl::set class for some of his code and whilst it compiled fine under","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.clearchain.com\/blog\/posts\/stlset","twitter_misc":{"Written by":"Benjamin Close","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.clearchain.com\/blog\/posts\/stlset#article","isPartOf":{"@id":"https:\/\/www.clearchain.com\/blog\/posts\/stlset"},"author":{"name":"Benjamin Close","@id":"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/aef6faa2c32188398139db9270ca1c98"},"headline":"stl::set","datePublished":"2008-11-13T14:26:24+00:00","dateModified":"2010-06-23T06:02:23+00:00","mainEntityOfPage":{"@id":"https:\/\/www.clearchain.com\/blog\/posts\/stlset"},"wordCount":167,"commentCount":3,"keywords":["iterator","stl"],"articleSection":["Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.clearchain.com\/blog\/posts\/stlset#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.clearchain.com\/blog\/posts\/stlset","url":"https:\/\/www.clearchain.com\/blog\/posts\/stlset","name":"stl::set - ClearChain","isPartOf":{"@id":"https:\/\/www.clearchain.com\/blog\/#website"},"datePublished":"2008-11-13T14:26:24+00:00","dateModified":"2010-06-23T06:02:23+00:00","author":{"@id":"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/aef6faa2c32188398139db9270ca1c98"},"description":"Working with Mark's dnl code, we came across an interesting issue. Mark had used the stl::set class for some of his code and whilst it compiled fine under","breadcrumb":{"@id":"https:\/\/www.clearchain.com\/blog\/posts\/stlset#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.clearchain.com\/blog\/posts\/stlset"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.clearchain.com\/blog\/posts\/stlset#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.clearchain.com\/blog"},{"@type":"ListItem","position":2,"name":"stl::set"}]},{"@type":"WebSite","@id":"https:\/\/www.clearchain.com\/blog\/#website","url":"https:\/\/www.clearchain.com\/blog\/","name":"ClearChain","description":"-= Daily Happenings =-","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.clearchain.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/aef6faa2c32188398139db9270ca1c98","name":"Benjamin Close","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.clearchain.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/19dca0aa372edfa901b93c556dfda2e78ad4434558fe4d139598e086315d714a?s=96&d=mm&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/19dca0aa372edfa901b93c556dfda2e78ad4434558fe4d139598e086315d714a?s=96&d=mm&r=pg","caption":"Benjamin Close"},"sameAs":["http:\/\/www.clearchain.com"]}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/posts\/125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/comments?post=125"}],"version-history":[{"count":2,"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/posts\/125\/revisions"}],"predecessor-version":[{"id":701,"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/posts\/125\/revisions\/701"}],"wp:attachment":[{"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/media?parent=125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/categories?post=125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.clearchain.com\/blog\/wp-json\/wp\/v2\/tags?post=125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}