diff --git a/include/boost/type_traits/decay.hpp b/include/boost/type_traits/decay.hpp new file mode 100755 index 0000000..1e978b2 --- /dev/null +++ b/include/boost/type_traits/decay.hpp @@ -0,0 +1,40 @@ +// (C) Copyright John Maddock & Thorsten Ottosen 2005. +// Use, modification and distribution are subject to 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). +// +// See http://www.boost.org/libs/type_traits for most recent version including documentation. + + +#ifndef BOOST_TT_DECAY_HPP_INCLUDED +#define BOOST_TT_DECAY_HPP_INCLUDED + +#include "boost/type_traits/config.hpp" +#include +#include +#include +#include +#include +#include + +namespace boost +{ + + template< class T > + struct decay + { + typedef typename mpl::eval_if< + is_array, + mpl::identity::type*>, + typename mpl::eval_if< + is_function, + add_pointer, + mpl::identity + > + >::type type; + }; + +} // namespace boost + + +#endif // BOOST_TT_DECAY_HPP_INCLUDED diff --git a/test/decay_test.cpp b/test/decay_test.cpp new file mode 100755 index 0000000..4c91b4b --- /dev/null +++ b/test/decay_test.cpp @@ -0,0 +1,113 @@ + +// (C) Copyright John Maddock & Thorsten Ottosen 2005. +// Use, modification and distribution are subject to 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) + +#include "test.hpp" +#include "check_integral_constant.hpp" +#ifdef TEST_STD +# include +#else +# include +# include +#endif +#include +#include +#include + +namespace boost +{ + + int proc1() + { + return 0; + } + int proc2(int c) + { + return c; + } + + // + // An almost optimal version of std::make_pair() + // + template< class F, class S > + inline std::pair< BOOST_DEDUCED_TYPENAME ::tt::decay::type, + BOOST_DEDUCED_TYPENAME ::tt::decay::type > + make_pair( const F& f, const S& s ) + { + return std::pair< BOOST_DEDUCED_TYPENAME ::tt::decay::type, + BOOST_DEDUCED_TYPENAME ::tt::decay::type >( f, s ); + } + + /* + This overload will f*** up vc7.1 + + template< class F, class S > + inline std::pair< BOOST_DEDUCED_TYPENAME ::tt::decay::type, + BOOST_DEDUCED_TYPENAME ::tt::decay::type > + make_pair( F& f, S& s ) + { + return std::pair< BOOST_DEDUCED_TYPENAME ::tt::decay::type, + BOOST_DEDUCED_TYPENAME ::tt::decay::type >( f, s ); + } + */ +} + +TT_TEST_BEGIN(is_class) + + BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< + ::tt::decay::type,int>::value), + true ); + BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< + ::tt::decay::type,char*>::value), + true ); + BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< + ::tt::decay::type,const char*>::value), + true ); + BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< + ::tt::decay::type,wchar_t*>::value), + true ); + BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< + ::tt::decay::type,const wchar_t*>::value), + true ); + BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< + ::tt::decay::type,const wchar_t*>::value), + true ); + BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< + ::tt::decay::type,int (*)(void)>::value), + true ); + BOOST_CHECK_INTEGRAL_CONSTANT((::tt::is_same< + ::tt::decay::type,int (*)(int)>::value), + true ); + + std::pair p = boost::make_pair( "foo", "bar" ); + std::pair p2 = boost::make_pair( "foo", 1 ); +#ifndef BOOST_NO_STD_WSTRING + std::pair p3 = boost::make_pair( L"foo", "bar" ); + std::pair p4 = boost::make_pair( L"foo", 1 ); +#endif + + // + // Todo: make these work sometime. The test id not directly + // related to decay::type and can be avioded for now. + // + /* + int array[10]; + std::pair p5 = boost::make_pair( array, array ); +#ifndef __BORLANDC__ + std::pair p6 = boost::make_pair(boost::proc1, boost::proc2); + p6.first(); + p6.second(1); +#endif + */ + +TT_TEST_END + + + + + + + +