#include <type_traits>
#include <iterator>
#include <vector>
template < typename T, typename = void >
struct is_const_iterator : std:: false_type { } ;
template < typename T>
struct is_const_iterator< T,
typename std:: enable_if <
std:: is_const <
typename std:: remove_pointer <
typename std:: iterator_traits < T> :: pointer
> :: type
> :: value
> :: type > : std:: true_type { } ;
template < typename It,
typename std:: enable_if < ! is_const_iterator< It> :: value > :: type * = nullptr>
void foo( It i)
{
// Does something with i...
}
int main( )
{
std:: vector < int > v;
foo( v.begin ( ) ) ; // OK
foo( v.cbegin ( ) ) ; // ERROR!
}
ICAgICNpbmNsdWRlIDx0eXBlX3RyYWl0cz4KICAgICNpbmNsdWRlIDxpdGVyYXRvcj4KICAgICNpbmNsdWRlIDx2ZWN0b3I+CgogICAgdGVtcGxhdGU8dHlwZW5hbWUgVCwgdHlwZW5hbWUgPSB2b2lkPgogICAgc3RydWN0IGlzX2NvbnN0X2l0ZXJhdG9yIDogc3RkOjpmYWxzZV90eXBlIHsgfTsKCiAgICB0ZW1wbGF0ZTx0eXBlbmFtZSBUPgogICAgc3RydWN0IGlzX2NvbnN0X2l0ZXJhdG9yPFQsCiAgICAgICAgdHlwZW5hbWUgc3RkOjplbmFibGVfaWY8CiAgICAgICAgICAgIHN0ZDo6aXNfY29uc3Q8CiAgICAgICAgICAgICAgICB0eXBlbmFtZSBzdGQ6OnJlbW92ZV9wb2ludGVyPAogICAgICAgICAgICAgICAgICAgIHR5cGVuYW1lIHN0ZDo6aXRlcmF0b3JfdHJhaXRzPFQ+Ojpwb2ludGVyCiAgICAgICAgICAgICAgICAgICAgPjo6dHlwZQogICAgICAgICAgICAgICAgPjo6dmFsdWUKICAgICAgICAgICAgPjo6dHlwZT4gOiBzdGQ6OnRydWVfdHlwZSB7IH07CgogICAgdGVtcGxhdGU8dHlwZW5hbWUgSXQsCiAgICAgICAgdHlwZW5hbWUgc3RkOjplbmFibGVfaWY8IWlzX2NvbnN0X2l0ZXJhdG9yPEl0Pjo6dmFsdWU+Ojp0eXBlKiA9IG51bGxwdHI+CiAgICB2b2lkIGZvbyhJdCBpKQogICAgewogICAgICAgIC8vIERvZXMgc29tZXRoaW5nIHdpdGggaS4uLgogICAgfQoKICAgIGludCBtYWluKCkKICAgIHsKICAgICAgICBzdGQ6OnZlY3RvcjxpbnQ+IHY7CiAgICAgICAgZm9vKHYuYmVnaW4oKSk7IC8vIE9LCiAgICAgICAgZm9vKHYuY2JlZ2luKCkpOyAvLyBFUlJPUiEKICAgIH0K
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:29:23: error: no matching function for call to ‘foo(std::vector<int>::const_iterator)’
prog.cpp:29:23: note: candidate is:
prog.cpp:20:10: note: template<class It, typename std::enable_if<(! is_const_iterator<It, void>::value), void>::type* <anonymous> > void foo(It)
prog.cpp:20:10: note: template argument deduction/substitution failed:
prog.cpp:19:73: error: no type named ‘type’ in ‘struct std::enable_if<false, void>’
prog.cpp:19:73: note: invalid template non-type parameter
stdout