Files
boost_mpl/include/boost/mpl/if.hpp
T

177 lines
4.0 KiB
C++
Raw Normal View History

2002-09-15 22:13:24 +00:00
//-----------------------------------------------------------------------------
// boost/mpl/if.hpp header file
// See http://www.boost.org for updates, documentation, and revision history.
//-----------------------------------------------------------------------------
//
// Copyright (c) 2000-02 Boost.org
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without fee,
// provided that the above copyright notice appears in all copies and
// that both the copyright notice and this permission notice appear in
// supporting documentation. No representations are made about the
// suitability of this software for any purpose. It is provided "as is"
// without express or implied warranty.
#ifndef BOOST_MPL_IF_HPP_INCLUDED
#define BOOST_MPL_IF_HPP_INCLUDED
#include "boost/mpl/aux_/value_wknd.hpp"
2002-12-09 05:20:25 +00:00
#include "boost/mpl/aux_/ice_cast.hpp"
2002-09-15 22:13:24 +00:00
#include "boost/mpl/aux_/void_spec.hpp"
#include "boost/mpl/aux_/lambda_support.hpp"
2003-02-04 20:21:36 +00:00
#include "boost/mpl/aux_/config/workaround.hpp"
2002-09-15 22:13:24 +00:00
#include "boost/config.hpp"
namespace boost {
namespace mpl {
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
template<
bool C
, typename T1
, typename T2
>
struct if_c
{
typedef T1 type;
};
template<
typename T1
, typename T2
>
struct if_c<false,T1,T2>
{
typedef T2 type;
};
template<
typename BOOST_MPL_AUX_VOID_SPEC_PARAM(C)
, typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T1)
, typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T2)
>
struct if_
{
2003-01-02 22:42:18 +00:00
private:
// agurt, 02/jan/03: two-step 'type' definition for the sake of aCC
typedef if_c<
2003-02-04 20:21:36 +00:00
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x561))
BOOST_MPL_AUX_VALUE_WKND(C)::value
#else
2002-12-09 05:20:25 +00:00
BOOST_MPL_AUX_ICE_CAST(bool, BOOST_MPL_AUX_VALUE_WKND(C)::value)
2003-02-04 20:21:36 +00:00
#endif
2002-09-15 22:13:24 +00:00
, T1
, T2
2003-01-02 22:42:18 +00:00
> almost_type_;
public:
typedef typename almost_type_::type type;
2002-09-15 22:13:24 +00:00
BOOST_MPL_AUX_LAMBDA_SUPPORT(3,if_,(C,T1,T2))
};
2002-09-17 08:35:18 +00:00
#elif defined(BOOST_MSVC) && (BOOST_MSVC <= 1300)
2002-09-15 22:13:24 +00:00
// MSVC6.5-specific version
template<
bool C_
2002-09-15 22:13:24 +00:00
, typename T1
, typename T2
>
struct if_c
{
private:
template<bool> struct answer { typedef T1 type; };
template<> struct answer<false> { typedef T2 type; };
public:
typedef typename answer< C_ >::type type;
2002-09-15 22:13:24 +00:00
};
// (almost) copy & paste in order to save one more
// recursively nested template instantiation to user
template<
typename C_
2002-09-15 22:13:24 +00:00
, typename T1
, typename T2
>
struct if_
{
private:
template<bool> struct answer { typedef T1 type; };
template<> struct answer<false> { typedef T2 type; };
2002-09-17 08:35:18 +00:00
// agurt, 17/sep/02: in some situations MSVC 7.0 doesn't
// handle 'answer<C::value>' expression very well
enum { c_ = C_::value };
2002-09-17 08:35:18 +00:00
2002-09-15 22:13:24 +00:00
public:
2002-12-09 05:20:25 +00:00
typedef typename answer< BOOST_MPL_AUX_ICE_CAST(bool, c_) >::type type;
2002-12-14 23:58:59 +00:00
BOOST_MPL_AUX_LAMBDA_SUPPORT(3,if_,(C_,T1,T2))
2002-09-15 22:13:24 +00:00
};
#else
// no partial class template specialization
namespace aux {
template< bool C >
struct if_impl
{
template< typename T1, typename T2 > struct result_
{
typedef T1 type;
};
};
template<>
struct if_impl<false>
{
template< typename T1, typename T2 > struct result_
{
typedef T2 type;
};
};
} // namespace aux
template<
bool C
, typename T1
, typename T2
>
struct if_c
{
typedef typename aux::if_impl< C >
::template result_<T1,T2>::type type;
};
// (almost) copy & paste in order to save one more
// recursively nested template instantiation to user
template<
typename BOOST_MPL_AUX_VOID_SPEC_PARAM(C)
, typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T1)
, typename BOOST_MPL_AUX_VOID_SPEC_PARAM(T2)
>
struct if_
{
2002-12-09 05:20:25 +00:00
typedef typename aux::if_impl< BOOST_MPL_AUX_ICE_CAST(bool, C::value) >
2002-09-15 22:13:24 +00:00
::template result_<T1,T2>::type type;
BOOST_MPL_AUX_LAMBDA_SUPPORT(3,if_,(C,T1,T2))
};
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
BOOST_MPL_AUX_VOID_SPEC(3, if_)
2002-09-17 11:11:20 +00:00
2002-09-15 22:13:24 +00:00
} // namespace mpl
} // namespace boost
#endif // BOOST_MPL_IF_HPP_INCLUDED