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

136 lines
2.8 KiB
C++
Raw Normal View History

2003-03-12 10:53:42 +00:00
#ifndef BOOST_MPL_IF_HPP_INCLUDED
#define BOOST_MPL_IF_HPP_INCLUDED
2004-09-02 15:41:37 +00:00
// Copyright Aleksey Gurtovoy 2000-2004
2002-09-15 22:13:24 +00:00
//
2004-09-02 15:41:37 +00:00
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
2003-03-12 10:53:42 +00:00
//
// See http://www.boost.org/libs/mpl for documentation.
2002-09-15 22:13:24 +00:00
2004-09-02 15:41:37 +00:00
// $Source$
// $Date$
// $Revision$
2002-09-15 22:13:24 +00:00
2004-09-02 15:41:37 +00:00
#include <boost/mpl/aux_/value_wknd.hpp>
#include <boost/mpl/aux_/static_cast.hpp>
#include <boost/mpl/aux_/na_spec.hpp>
#include <boost/mpl/aux_/lambda_support.hpp>
2004-09-07 08:53:22 +00:00
#include <boost/mpl/aux_/config/integral.hpp>
2004-09-02 15:41:37 +00:00
#include <boost/mpl/aux_/config/ctps.hpp>
#include <boost/mpl/aux_/config/workaround.hpp>
2003-04-28 04:55:23 +00:00
2004-09-02 15:41:37 +00:00
namespace boost { namespace mpl {
2002-09-15 22:13:24 +00:00
#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;
};
2004-09-05 11:41:08 +00:00
// agurt, 05/sep/04: nondescriptive parameter names for the sake of DigitalMars
// (and possibly MWCW < 8.0); see http://article.gmane.org/gmane.comp.lib.boost.devel/108959
2002-09-15 22:13:24 +00:00
template<
2004-09-05 11:41:08 +00:00
typename BOOST_MPL_AUX_NA_PARAM(T1)
2004-09-02 15:41:37 +00:00
, typename BOOST_MPL_AUX_NA_PARAM(T2)
2004-09-05 11:41:08 +00:00
, typename BOOST_MPL_AUX_NA_PARAM(T3)
2002-09-15 22:13:24 +00:00
>
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<
2004-09-02 15:41:37 +00:00
#if defined(BOOST_MPL_CFG_BCC_INTEGRAL_CONSTANTS)
2004-09-05 11:41:08 +00:00
BOOST_MPL_AUX_VALUE_WKND(T1)::value
2003-02-04 20:21:36 +00:00
#else
2004-09-05 11:41:08 +00:00
BOOST_MPL_AUX_STATIC_CAST(bool, BOOST_MPL_AUX_VALUE_WKND(T1)::value)
2003-02-04 20:21:36 +00:00
#endif
2002-09-15 22:13:24 +00:00
, T2
2004-09-05 11:41:08 +00:00
, T3
2003-01-02 22:42:18 +00:00
> almost_type_;
public:
typedef typename almost_type_::type type;
2004-09-05 11:41:08 +00:00
BOOST_MPL_AUX_LAMBDA_SUPPORT(3,if_,(T1,T2,T3))
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_
2002-09-15 22:13:24 +00:00
, typename T1
, typename T2
>
struct if_c
{
typedef typename aux::if_impl< C_ >
2002-09-15 22:13:24 +00:00
::template result_<T1,T2>::type type;
};
// (almost) copy & paste in order to save one more
// recursively nested template instantiation to user
template<
2004-09-02 15:41:37 +00:00
typename BOOST_MPL_AUX_NA_PARAM(C_)
, typename BOOST_MPL_AUX_NA_PARAM(T1)
, typename BOOST_MPL_AUX_NA_PARAM(T2)
2002-09-15 22:13:24 +00:00
>
struct if_
{
2004-09-02 15:41:37 +00:00
enum { msvc_wknd_ = BOOST_MPL_AUX_MSVC_VALUE_WKND(C_)::value };
2004-09-02 15:41:37 +00:00
typedef typename aux::if_impl< BOOST_MPL_AUX_STATIC_CAST(bool, msvc_wknd_) >
2002-09-15 22:13:24 +00:00
::template result_<T1,T2>::type type;
BOOST_MPL_AUX_LAMBDA_SUPPORT(3,if_,(C_,T1,T2))
2002-09-15 22:13:24 +00:00
};
#endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
2004-09-02 15:41:37 +00:00
BOOST_MPL_AUX_NA_SPEC(3, if_)
2003-09-18 07:39:27 +00:00
2004-09-02 15:41:37 +00:00
}}
2002-09-15 22:13:24 +00:00
#endif // BOOST_MPL_IF_HPP_INCLUDED