Boost logo

Boost Users :

Subject: [Boost-users] request: plz add operator() to mpl::true_ and mpl::false_
From: Niitsuma Hirotaka (hirotaka.niitsuma_at_[hidden])
Date: 2012-08-12 14:15:01


plz add operator() to mpl::true_ and mpl_::false

let us consider the following case.

struct foo{};

template<typename T> struct
is_foo_traits : boost::mpl::false_ {};

template<> struct
is_foo_traits<foo> : boost::mpl::true_ {};

template<typename T> bool
is_foo(const T& dummy){return false;}

template<>
bool is_foo<foo>(const foo& dummy){return true;}

void main()
{
  using namespace boost;
  using namespace std;
  foo myfoo;
  cout << is_foo(myfoo) << endl;//true
  cout << is_foo(12) << endl;//false
  cout << is_foo_traits<foo>::value << endl;//true
  cout << is_foo_traits<int>::value << endl;//false

}

In this case, we need to define same thing two times.
However if mpl::true_ have operator() as like

mpl::true_
{
template<typename T>
bool operator()(const T & dummy){return true;}
};

We can remove one line using:

template<typename T> bool is_foo(const T& dummy){return
is_foo_traits<T>::value;}


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