c++ - Type trait through a variable of the type -


i'd test property of type of variable. can it, code verbose.

consider example, in define variable of same type type of value in container:

#include <vector>  int main() {   std::vector<int> v, &rv=v;    // ‘rv’ not class, namespace, or enumeration   //rv::value_type i1;    // ok   decltype(v)::value_type i2;    // decltype evaluates ‘std::vector<int>&’, not class or enumeration type   //decltype(rv)::value_type i3;    // ok   std::remove_reference<decltype(rv)>::type::value_type i4; } 

i can live decltype, adding std::remove_reference much. there nice way shorten code, without defining auxiliary templates?

you can shorten 1 of

std::decay_t<decltype(rv)>::value_type i4 = 42; 

or

std::decay_t<decltype(*std::begin(rv))> i4 = 42; 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -