how to use C++11 integral_constant::value_type() -



how to use C++11 integral_constant::value_type() -

i learning utilize c++ 11 type_traits, in integral_constant, there function value_type();

i tried got error:

typedef std::integral_constant<int, 1> one_t; one_t one_o; one_o.value_type();

../src/main.cc:13:9: error: cannot refer type fellow member 'value_type' in 'one_t' (aka 'integral_constant') '.' one_o.value_type();

well function value_type() not function name. indeed, definition of integral_constant looks this:

template <class t, t v> struct integral_constant { // ... typedef t value_type; constexpr operator value_type() const noexcept { homecoming value; } };

notice value_type typedef template parameter t (int, in op's example). in add-on there's conversion operator converts integral_constant<t, v> t. it's implicitly called this

int = one_o; // same int = 1;

to phone call explicitly need utilize operator keyword , right type this:

one_o.operator int();

which, typedef member, equivalent to

one_o.operator one_t::value_type();

c++11

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -