id,summary,reporter,owner,description,type,status,milestone,component,version,severity,resolution,keywords,cc 13644,std::iterator_traits<>::value_type is always non-const for any kind of boost::iterator_facade Iterator,Florian Reiser ,jeffrey.hellrung,"I've found a bug in boost::iterator_facade. If you define your own iterator by using the facade and you try to deduce the value_type of the iterator by using std::iterator_traits, the type is always non-const independently of the iterator value type declaration. You can reproduce this with the following test program: {{{ #!C++ #include #include template class IteratorTest : public boost::iterator_facade< IteratorTest , Value , boost::forward_traversal_tag > { public: IteratorTest() {}; private: Value m_value{}; friend class boost::iterator_core_access; template friend class IteratorTest; template inline bool equal(const IteratorTest& other) const { return true; } void increment() { } inline Value& dereference() const noexcept { return m_value; } }; template class DeduceType; int main() { using iterator = IteratorTest; using const_iterator = IteratorTest; auto it = iterator(); auto cit = const_iterator(); DeduceType debug1; DeduceType debug2; DeduceType> debug3; DeduceType> debug4; } }}} With my VS2017 compiler, I receive the following compiler output (I've omitted the implementation of !DeduceType to force the compiler to tell me the type; so the compiler error here is not an Error) {{{ 1>c:\users\florian\source\repos\iterator_facade_const_bug\iterator_facade_const_bug\reproducebug.cpp(46): error C2079: 'debug1' uses undefined class 'DeduceType' 1>c:\users\florian\source\repos\iterator_facade_const_bug\iterator_facade_const_bug\reproducebug.cpp(47): error C2079: 'debug2' uses undefined class 'DeduceType' 1>c:\users\florian\source\repos\iterator_facade_const_bug\iterator_facade_const_bug\reproducebug.cpp(48): error C2079: 'debug3' uses undefined class 'DeduceType>' 1>c:\users\florian\source\repos\iterator_facade_const_bug\iterator_facade_const_bug\reproducebug.cpp(49): error C2079: 'debug4' uses undefined class 'DeduceType>' }}} I've found the reason for this bug in boost/iterator/iterator_facade.hpp:120 {{{ #!C++ template < class ValueParam , class CategoryOrTraversal , class Reference , class Difference > struct iterator_facade_types { typedef typename facade_iterator_category< CategoryOrTraversal, ValueParam, Reference >::type iterator_category; typedef typename remove_const::type value_type; }}} If you change the line {{{ #!C++ typedef typename remove_const::type value_type; }}} to {{{ #!C++ typedef ValueParam value_type; }}} the output of my test program is as expected: {{{ 1>c:\users\florian\source\repos\iterator_facade_const_bug\iterator_facade_const_bug\reproducebug.cpp(46): error C2079: 'debug1' uses undefined class 'DeduceType' 1>c:\users\florian\source\repos\iterator_facade_const_bug\iterator_facade_const_bug\reproducebug.cpp(47): error C2079: 'debug2' uses undefined class 'DeduceType' 1>c:\users\florian\source\repos\iterator_facade_const_bug\iterator_facade_const_bug\reproducebug.cpp(48): error C2079: 'debug3' uses undefined class 'DeduceType>' 1>c:\users\florian\source\repos\iterator_facade_const_bug\iterator_facade_const_bug\reproducebug.cpp(49): error C2079: 'debug4' uses undefined class 'DeduceType>' }}}",Bugs,new,To Be Determined,iterator,Boost 1.67.0,Problem,,iterator_facade,