X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2Ftype_traits.hh;h=74d6770d38cc3a78117f8eeb07acb5b2abc418c9;hb=refs%2Fheads%2Fmaster;hp=a728ac0928f914b3710379c7c7d59155635201e2;hpb=26610f603ebdd465307b9621f532c1fe19fd5571;p=senf.git diff --git a/senf/Utils/type_traits.hh b/senf/Utils/type_traits.hh index a728ac0..74d6770 100644 --- a/senf/Utils/type_traits.hh +++ b/senf/Utils/type_traits.hh @@ -1,24 +1,29 @@ // $Id$ // -// Copyright (C) 2008 +// Copyright (C) 2008 // Fraunhofer Institute for Open Communication Systems (FOKUS) -// Competence Center NETwork research (NET), St. Augustin, GERMANY -// Stefan Bund // -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. +// The contents of this file are subject to the Fraunhofer FOKUS Public License +// Version 1.0 (the "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// http://senf.berlios.de/license.html // -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. +// The Fraunhofer FOKUS Public License Version 1.0 is based on, +// but modifies the Mozilla Public License Version 1.1. +// See the full license text for the amendments. // -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the -// Free Software Foundation, Inc., -// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// Software distributed under the License is distributed on an "AS IS" basis, +// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License +// for the specific language governing rights and limitations under the License. +// +// The Original Code is Fraunhofer FOKUS code. +// +// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. +// (registered association), Hansastraße 27 c, 80686 Munich, Germany. +// All Rights Reserved. +// +// Contributor(s): +// Stefan Bund /** \file \brief type_traits public header */ @@ -36,7 +41,7 @@ #include #include "type_traits.mpp" -///////////////////////////////hh.p//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// namespace senf { @@ -45,7 +50,7 @@ namespace senf */ ///\addtogroup typetraits - ///\{ + //\{ /** \brief Strip first parameter from function traits @@ -54,12 +59,12 @@ namespace senf If the function described in \a Traits does not take any arguments, it is returned unchanged. - + \code typedef boost::function_traits traits - BOOST_STATIC_ASSERT(( boost::is_same< - senf::function_traits_remove_arg< traits >::type, - boost::function_traits + BOOST_STATIC_ASSERT(( boost::is_same< + senf::function_traits_remove_arg< traits >::type, + boost::function_traits >::value )); \endcode @@ -69,7 +74,7 @@ namespace senf struct function_traits_remove_arg {}; /** \brief Get argument type from function traits - + function_traits_arg will return the type of the \a index-th argument from \a Traits. If the function has no argument at that index, \c void is returned @@ -77,18 +82,18 @@ namespace senf typedef boost::function_traits traits; BOOST_STATIC_ASSERT(( boost:is_same< senf::function_traits_arg_type< traits, 0 >::type, - int + int >::value )); BOOST_STATIC_ASSERT(( boost::is_same< senf::function_traits_arg_type< traits, 2 >::type, void >::value )); \endcode - + \tparam Traits \c boost::function_traits instantiation \tparam index 0 based argument index */ - template < class Traits, int index, bool flag = (index < Traits::arity) > + template < class Traits, int index, bool flag = (index < Traits::arity) > struct function_traits_arg_type {}; #ifndef DOXYGEN @@ -107,12 +112,12 @@ namespace senf will be returned unchanged. \code - BOOST_STATIC_ASSERT(( boost::is_same< - senf::remove_member_pointer< int (Class::*) >::type, - int + BOOST_STATIC_ASSERT(( boost::is_same< + senf::remove_member_pointer< int (Class::*) >::type, + int >::value )); - BOOST_STATIC_ASSERT(( boost::is_same< - senf::remove_member_pointer< void (Class::*)(int) >::type, + BOOST_STATIC_ASSERT(( boost::is_same< + senf::remove_member_pointer< void (Class::*)(int) >::type, void (int) >::value )); \endcode @@ -160,7 +165,7 @@ namespace senf { typedef void type; }; - + #ifndef DOXYGEN template < class C, class T > struct member_class @@ -179,14 +184,14 @@ namespace senf This meta function will remove a plain or member pointer from the given type. If \a T is neither a member pointer nor an ordinary pointer, \a T will be returned unchanged. - + \code - BOOST_STATIC_ASSERT(( boost::is_same< - senf::remove_any_pointer< int (Class::*) >::type, + BOOST_STATIC_ASSERT(( boost::is_same< + senf::remove_any_pointer< int (Class::*) >::type, int >::value )); - BOOST_STATIC_ASSERT(( boost::is_same< - senf::remove_any_pointer< void (Class::*)(int) >::type, + BOOST_STATIC_ASSERT(( boost::is_same< + senf::remove_any_pointer< void (Class::*)(int) >::type, void (int) > ); BOOST_STATIC_ASSERT(( boost::is_same< senf::remove_any_pointer < int (*)() >::type, @@ -206,7 +211,7 @@ namespace senf {}; /** \brief Test object if it is a function or member-function (pointer) - + is_any_function will inherit from \c boost::true_type, when \a T is a function type, function pointer type or a member function pointer type. Otherwise, it will inherit from \c boost::false_type. @@ -226,7 +231,7 @@ namespace senf {}; /** \brief Remove reference and CV qualification from type - + remove_cvref will remove all the 'ornaments' from a type as typically used to pass arguments: references and any CV spec. It will thus convert a typical argument type into it's basic type. @@ -243,7 +248,46 @@ namespace senf : public boost::remove_cv< typename boost::remove_reference::type > {}; - ///} + /** \brief Get arity of function T + + \a T may be any function like type: function, pointer to function or (pointer to) + member-function. + + \code + BOOST_STATIC_ASSERT(( senf::function_arity::value == 1 )); + \endcode + */ + template < class T > + struct function_arity + : public boost::integral_constant< + unsigned, + boost::function_traits< + typename senf::remove_any_pointer::type>::arity> + {}; + + /** Test object if it is any \c std::pair type + + if \a Pair is any \c std::pair type, this trait will inherit from \c boost::true_type, + otherwise it will inherit from \c boost::false_type. + + \code + BOOST_STATIC_ASSERT(( senf::is_pair< std::pair >::value )); + BOOST_STATIC_ASSERT(( ! senf::is_pair< void () >::value )); + \endcode + */ + template + struct is_pair + : public boost::false_type + {}; + +#ifndef DOXYGEN + template + struct is_pair< std::pair > + : public boost::true_type + {}; +#endif + + //\} #ifndef DOXYGEN @@ -256,13 +300,13 @@ namespace senf } -///////////////////////////////hh.e//////////////////////////////////////// +//-///////////////////////////////////////////////////////////////////////////////////////////////// //#include "type_traits.cci" //#include "type_traits.ct" //#include "type_traits.cti" #endif - + // Local Variables: // mode: c++ // fill-column: 100