Boost logo

Boost Users :

Subject: [Boost-users] is_foo_type naming rule
From: Niitsuma Hirotaka (hirotaka.niitsuma_at_[hidden])
Date: 2013-03-07 23:57:10


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;
---------


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net