There are two type is_foo_type functor For example is_double can be --------- template<typename T> struct is_double_template : boost::is_same<T,double> {}; --------- or --------- struct is_double_runtime { template<typename T> bool operator()(T x){return false;} bool operator()(double x){return true;} }; --------- Are there any standard naming rule distinguish these functor? is_foo_runtime is_foo_compiletime ? The compile-time functor can convert to runtime factor using : --------- template<typename IsTemplateMplLambda> struct is_templated_type_to_runtime { typedef struct is_templated_type_runtime { template<typename T> bool operator()(T) { return boost::mpl::apply<IsTemplateMplLambda,T>::type::value; } } type; }; --------- usage --------- typedef boost::mpl::lambda<is_double_template<boost::mpl::_1 >
::type is_double_mpl_lambda;
double x=1.1; int i=2; is_templated_type_to_runtime<is_double_mpl_lambda>::type is_double_runtime_object; std::cout << is_double_runtime_object(x) << std::endl; std::cout << is_double_runtime_object(i) << std::endl; ---------
On Thu, Mar 7, 2013 at 8:57 PM, Niitsuma Hirotaka < hirotaka.niitsuma@gmail.com> wrote:
There are two type is_foo_type functor For example is_double can be
--------- template<typename T> struct is_double_template : boost::is_same<T,double> {}; ---------
or
--------- struct is_double_runtime { template<typename T> bool operator()(T x){return false;} bool operator()(double x){return true;} }; ---------
Are there any standard naming rule distinguish these functor?
I don't think so, but reasonable alternatives are: - Name them the same thing (union the above definitions). - Name the structs the same, but put them in different namespaces (e.g., mpl and functional). - Name them static_foo and foo (this is the convention used by Boost.Math, I think, for integer functions). is_foo_runtime
is_foo_compiletime ?
The compile-time functor can convert to runtime factor using :
--------- template<typename IsTemplateMplLambda> struct is_templated_type_to_runtime { typedef struct is_templated_type_runtime { template<typename T> bool operator()(T) { return boost::mpl::apply<IsTemplateMplLambda,T>::type::value; } } type; };
Oh, so then what do you need the runtime foo one for? :) - Jeff
If boost::type_traits includes the following converter from compile-time to run-time "is_foo" , we don't need consider such naming problem
Are there any standard naming rule distinguish these functor?
I don't think so, but reasonable alternatives are: - Name them the same thing (union the above definitions). - Name the structs the same, but put them in different namespaces (e.g., mpl and functional). - Name them static_foo and foo (this is the convention used by Boost.Math, I think, for integer functions).
is_foo_runtime is_foo_compiletime ?
The compile-time functor can convert to runtime factor using :
--------- template<typename IsTemplateMplLambda> struct is_templated_type_to_runtime { typedef struct is_templated_type_runtime { template<typename T> bool operator()(T) { return boost::mpl::apply<IsTemplateMplLambda,T>::type::value; } } type; };
Oh, so then what do you need the runtime foo one for? :)
When - getting at(N) from boost.fusion.list<T1,T2,T3....> type information need in run-time :T_N
2013/3/8 Niitsuma Hirotaka <hirotaka.niitsuma@gmail.com>:
There are two type is_foo_type functor For example is_double can be
--------- template<typename T> struct is_double_template : boost::is_same<T,double> {}; ---------
or
--------- struct is_double_runtime { template<typename T> bool operator()(T x){return false;} bool operator()(double x){return true;} };
Why don't you just use BOOST_TYPEOF(x) macro? T d; std::cout << is_double<T>::value << std::endl; std::cout << is_double<BOOST_TYPEOF(d)>::value << std::endl; -- Best regards, Antony Polukhin
participants (3)
-
Antony Polukhin
-
Jeffrey Lee Hellrung, Jr.
-
Niitsuma Hirotaka