|
Boost : |
Subject: Re: [boost] New dependency report
From: Peter Dimov (lists_at_[hidden])
Date: 2014-06-07 11:46:19
John Maddock wrote:
> >> In fact in C++11 it makes sense to me have:
> >>
> >> namespace boost{ namespace mpl{
> >>
> >> template <bool b>
> >> using bool_ = std::integral_constant<bool, b>;
I have another solution, which appears good enough to go into Core. We could
also enhance mpl::bool_ in the same way. Note that the trait knows nothing
about bool_, but dispatch still works.
#include <boost/config.hpp>
#include <boost/core/enable_if.hpp>
//
template< bool V > struct bool_
{
BOOST_STATIC_CONSTANT( bool, value = V );
template< class T > bool_( T const &, typename boost::enable_if_c<
T::value == V >::type * = 0 )
{
}
};
typedef bool_< false > false_;
typedef bool_< true > true_;
//
#include <boost/core/lightweight_test.hpp>
template< class T > struct is_pointer
{
BOOST_STATIC_CONSTANT( bool, value = false );
};
template< class T > struct is_pointer< T* >
{
BOOST_STATIC_CONSTANT( bool, value = true );
};
int f( true_ )
{
return 5;
}
int f( false_ )
{
return 11;
}
int main()
{
BOOST_TEST( f( is_pointer< int* >() ) == 5 );
BOOST_TEST( f( is_pointer< int >() ) == 11 );
return boost::report_errors();
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk