$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r82065 - in trunk: boost/tti boost/tti/detail boost/tti/gen libs/tti/test
From: eldiener_at_[hidden]
Date: 2012-12-17 23:20:01
Author: eldiener
Date: 2012-12-17 23:19:59 EST (Mon, 17 Dec 2012)
New Revision: 82065
URL: http://svn.boost.org/trac/boost/changeset/82065
Log:
Implementation and tests for BOOST_TTI_HAS_FUNCTION
Added:
   trunk/boost/tti/detail/dfunction.hpp   (contents, props changed)
   trunk/boost/tti/gen/has_function_gen.hpp   (contents, props changed)
   trunk/boost/tti/has_function.hpp   (contents, props changed)
   trunk/libs/tti/test/test_has_fun.cpp   (contents, props changed)
   trunk/libs/tti/test/test_has_fun.hpp   (contents, props changed)
   trunk/libs/tti/test/test_has_fun_compile.cpp   (contents, props changed)
   trunk/libs/tti/test/test_has_fun_fail.cpp   (contents, props changed)
   trunk/libs/tti/test/test_has_fun_fail2.cpp   (contents, props changed)
   trunk/libs/tti/test/test_has_fun_fail3.cpp   (contents, props changed)
   trunk/libs/tti/test/test_has_fun_fail4.cpp   (contents, props changed)
Text files modified: 
   trunk/boost/tti/detail/dptmf.hpp |    15 ++++++++++++---                         
   trunk/libs/tti/test/Jamfile.v2   |    16 +++++++++++++++-                        
   2 files changed, 27 insertions(+), 4 deletions(-)
Added: trunk/boost/tti/detail/dfunction.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/tti/detail/dfunction.hpp	2012-12-17 23:19:59 EST (Mon, 17 Dec 2012)
@@ -0,0 +1,43 @@
+
+//  (C) Copyright Edward Diener 2012
+//  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).
+
+#if !defined(BOOST_TTI_DETAIL_FUNCTION_HPP)
+#define BOOST_TTI_DETAIL_FUNCTION_HPP
+
+#include <boost/config.hpp>
+#include <boost/preprocessor/cat.hpp>
+#include <boost/tti/detail/dmem_fun.hpp>
+#include <boost/tti/detail/dstatic_mem_fun.hpp>
+#include <boost/tti/gen/namespace_gen.hpp>
+
+#define BOOST_TTI_DETAIL_TRAIT_HAS_FUNCTION(trait,name) \
+  BOOST_TTI_DETAIL_TRAIT_HAS_CALL_TYPES_MEMBER_FUNCTION(trait,name) \
+  BOOST_TTI_DETAIL_TRAIT_IMPL_HAS_STATIC_MEMBER_FUNCTION(trait,name) \
+  template<class TTI_T,class TTI_R,class TTI_FS,class TTI_TAG> \
+  struct BOOST_PP_CAT(trait,_detail_hf) \
+    { \
+    \
+    typedef typename \
+    BOOST_PP_CAT(trait,_detail_call_types)<TTI_T,TTI_R,TTI_FS,TTI_TAG>::type hmftype; \
+    \
+    typedef typename \
+    BOOST_PP_CAT(trait,_detail_ihsmf) \
+      < \
+      TTI_T, \
+      typename BOOST_TTI_NAMESPACE::detail::tfunction_seq<TTI_R,TTI_FS,TTI_TAG>::type \
+      >::type hsmftype; \
+    \
+    BOOST_STATIC_CONSTANT \
+      ( \
+      bool, \
+      value = hmftype::value || hsmftype::value \
+      ); \
+    \
+    typedef boost::mpl::bool_<value> type; \
+    }; \
+/**/
+
+#endif // BOOST_TTI_DETAIL_FUNCTION_HPP
Modified: trunk/boost/tti/detail/dptmf.hpp
==============================================================================
--- trunk/boost/tti/detail/dptmf.hpp	(original)
+++ trunk/boost/tti/detail/dptmf.hpp	2012-12-17 23:19:59 EST (Mon, 17 Dec 2012)
@@ -26,9 +26,18 @@
         >
       struct ptmf_seq
         {
-        typedef typename boost::mpl::push_front<FS,T>::type tfs1;
-        typedef typename boost::mpl::push_front<tfs1,R>::type tfs2;
-        typedef typename boost::function_types::member_function_pointer<tfs2,TAG>::type type;
+        typedef typename
+        boost::function_types::member_function_pointer
+          <
+          typename
+          boost::mpl::push_front
+            <
+            typename
+            boost::mpl::push_front<FS,T>::type,
+            R
+            >::type,
+          TAG
+          >::type type;
         };
       }
     }
Added: trunk/boost/tti/gen/has_function_gen.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/tti/gen/has_function_gen.hpp	2012-12-17 23:19:59 EST (Mon, 17 Dec 2012)
@@ -0,0 +1,31 @@
+
+//  (C) Copyright Edward Diener 2012
+//  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).
+
+#if !defined(BOOST_TTI_FUNCTION_GEN_HPP)
+#define BOOST_TTI_FUNCTION_GEN_HPP
+
+#include <boost/preprocessor/cat.hpp>
+
+/*
+
+  The succeeding comments in this file are in doxygen format.
+
+*/
+
+/** \file
+*/
+
+/// Generates the macro metafunction name for BOOST_TTI_HAS_FUNCTION.
+/**
+    name  = the name of the static member function.
+
+    returns = the generated macro metafunction name.
+*/
+#define BOOST_TTI_HAS_FUNCTION_GEN(name) \
+  BOOST_PP_CAT(has_function_,name) \
+/**/
+
+#endif // BOOST_TTI_FUNCTION_GEN_HPP
Added: trunk/boost/tti/has_function.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/tti/has_function.hpp	2012-12-17 23:19:59 EST (Mon, 17 Dec 2012)
@@ -0,0 +1,106 @@
+
+//  (C) Copyright Edward Diener 2012
+//  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).
+
+#if !defined(BOOST_TTI_HAS_FUNCTION_HPP)
+#define BOOST_TTI_HAS_FUNCTION_HPP
+
+#include <boost/function_types/property_tags.hpp>
+#include <boost/mpl/vector.hpp>
+#include <boost/preprocessor/cat.hpp>
+#include <boost/tti/detail/dfunction.hpp>
+#include <boost/tti/gen/has_function_gen.hpp>
+
+/*
+
+  The succeeding comments in this file are in doxygen format.
+
+*/
+
+/** \file
+*/
+
+/// Expands to a metafunction which tests whether a member function or a static member function with a particular name and signature exists.
+/**
+
+    trait = the name of the metafunction within the tti namespace.
+    
+    name  = the name of the inner member.
+
+    generates a metafunction called "trait" where 'trait' is the macro parameter.
+    
+              template<class TTI_T,class TTI_R,class TTI_FS,class TTI_TAG>
+              struct trait
+                {
+                static const value = unspecified;
+                typedef mpl::bool_<true-or-false> type;
+                };
+
+              The metafunction types and return:
+    
+                TTI_T   = the enclosing type in which to look for our 'name'.
+                
+                TTI_R   = the return type of the function
+                
+                TTI_FS  = (optional) the parameters of the function as a boost::mpl forward sequence
+                          if the second parameter is a return type and the function parameters exist.
+                
+                TTI_TAG = (optional) a boost::function_types tag to apply to the function
+                          if the second parameter is a return type and the need for a tag exists.
+                
+                returns = 'value' is true if the 'name' exists, 
+                          with the appropriate static member function type,
+                          otherwise 'value' is false.
+                          
+*/
+#define BOOST_TTI_TRAIT_HAS_FUNCTION(trait,name) \
+  BOOST_TTI_DETAIL_TRAIT_HAS_FUNCTION(trait,name) \
+  template<class TTI_T,class TTI_R,class TTI_FS = boost::mpl::vector<>,class TTI_TAG = boost::function_types::null_tag> \
+  struct trait : \
+    BOOST_PP_CAT(trait,_detail_hf)<TTI_T,TTI_R,TTI_FS,TTI_TAG> \
+    { \
+    }; \
+/**/
+
+/// Expands to a metafunction which tests whether a member function or a static member function with a particular name and signature exists.
+/**
+
+    name  = the name of the inner member.
+
+    generates a metafunction called "has_function_name" where 'name' is the macro parameter.
+    
+              template<class TTI_T,class TTI_R,class TTI_FS,class TTI_TAG>
+              struct trait
+                {
+                static const value = unspecified;
+                typedef mpl::bool_<true-or-false> type;
+                };
+
+              The metafunction types and return:
+    
+                TTI_T   = the enclosing type in which to look for our 'name'.
+                
+                TTI_R   = the return type of the function
+                
+                TTI_FS  = (optional) the parameters of the function as a boost::mpl forward sequence
+                          if the second parameter is a return type and the function parameters exist.
+                
+                TTI_TAG = (optional) a boost::function_types tag to apply to the function
+                          if the second parameter is a return type and the need for a tag exists.
+                
+                returns = 'value' is true if the 'name' exists, 
+                          with the appropriate function type,
+                          otherwise 'value' is false.
+                          
+*/
+#define BOOST_TTI_HAS_FUNCTION(name) \
+  BOOST_TTI_TRAIT_HAS_FUNCTION \
+  ( \
+  BOOST_TTI_HAS_FUNCTION_GEN(name), \
+  name \
+  ) \
+/**/
+
+#endif // BOOST_TTI_HAS_FUNCTION_HPP
Modified: trunk/libs/tti/test/Jamfile.v2
==============================================================================
--- trunk/libs/tti/test/Jamfile.v2	(original)
+++ trunk/libs/tti/test/Jamfile.v2	2012-12-17 23:19:59 EST (Mon, 17 Dec 2012)
@@ -1,4 +1,5 @@
-#  (C) Copyright Edward Diener 2011
+
+#  (C) Copyright Edward Diener 2011,2012
 #  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).
@@ -104,6 +105,19 @@
     ;
 
 #
+# Member or static member function
+#
+alias ttifun
+    :
+        [ run test_has_fun.cpp ]
+        [ compile test_has_fun_compile.cpp ]
+        [ compile-fail test_has_fun_fail.cpp ]
+        [ compile-fail test_has_fun_fail2.cpp ]
+        [ compile-fail test_has_fun_fail3.cpp ]
+        [ compile-fail test_has_fun_fail4.cpp ]
+    ;
+
+#
 # Templates 
 #
 alias ttitmp
Added: trunk/libs/tti/test/test_has_fun.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/tti/test/test_has_fun.cpp	2012-12-17 23:19:59 EST (Mon, 17 Dec 2012)
@@ -0,0 +1,29 @@
+
+//  (C) Copyright Edward Diener 2012
+//  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_has_fun.hpp"
+#include <boost/detail/lightweight_test.hpp>
+
+int main()
+  {
+  
+  BOOST_TEST((BOOST_TTI_HAS_FUNCTION_GEN(VoidFunction)<AType,void>::value));
+  BOOST_TEST((HaveTheSIntFunction<AType,int,boost::mpl::vector<long,double> >::value));
+  BOOST_TEST((BOOST_TTI_HAS_FUNCTION_GEN(TSFunction)<AnotherType,AType::AStructType,boost::mpl::vector<AType::AnIntType,double> >::value));
+  BOOST_TEST((FunctionReturningInt<AType,int>::value));
+  BOOST_TEST((!Pickedname<AnotherType,void>::value));
+  BOOST_TEST((!TheTIntFunction<AType,AType,boost::mpl::vector<long,double> >::value));
+  BOOST_TEST((FunctionReturningInt<AnotherType,double,boost::mpl::vector<int> >::value));
+  BOOST_TEST((BOOST_TTI_HAS_FUNCTION_GEN(aFunction)<AnotherType,AType,boost::mpl::vector<int> >::value));
+  BOOST_TEST((AnotherIntFunction<AnotherType,int,boost::mpl::vector<AType> >::value));
+  BOOST_TEST((BOOST_TTI_HAS_FUNCTION_GEN(sFunction)<AnotherType,AType::AnIntType,boost::mpl::vector<int,long,double> >::value));
+  BOOST_TEST((!BOOST_TTI_HAS_FUNCTION_GEN(someFunctionMember)<AnotherType,AType,boost::mpl::vector<long,int> >::value));
+  BOOST_TEST((TheTIntFunction<AnotherType,AType,boost::mpl::vector<long,double> >::value));
+  BOOST_TEST((BOOST_TTI_HAS_FUNCTION_GEN(PublicIntFunction)<AnotherType,double,boost::mpl::vector<int> >::value));
+  
+  return boost::report_errors();
+
+  }
Added: trunk/libs/tti/test/test_has_fun.hpp
==============================================================================
--- (empty file)
+++ trunk/libs/tti/test/test_has_fun.hpp	2012-12-17 23:19:59 EST (Mon, 17 Dec 2012)
@@ -0,0 +1,25 @@
+
+//  (C) Copyright Edward Diener 2012
+//  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).
+
+#if !defined(BOOST_TEST_HAS_FUNCTION_HPP)
+#define BOOST_TEST_HAS_FUNCTION_HPP
+
+#include "test_structs.hpp"
+#include <boost/tti/has_function.hpp>
+
+BOOST_TTI_HAS_FUNCTION(VoidFunction)
+BOOST_TTI_TRAIT_HAS_FUNCTION(TheTIntFunction,TIntFunction)
+BOOST_TTI_TRAIT_HAS_FUNCTION(FunctionReturningInt,IntFunction)
+BOOST_TTI_HAS_FUNCTION(aFunction)
+BOOST_TTI_TRAIT_HAS_FUNCTION(AnotherIntFunction,anotherFunction)
+BOOST_TTI_TRAIT_HAS_FUNCTION(Pickedname,SomeStaticFunction)
+BOOST_TTI_HAS_FUNCTION(sFunction)
+BOOST_TTI_HAS_FUNCTION(someFunctionMember)
+BOOST_TTI_TRAIT_HAS_FUNCTION(HaveTheSIntFunction,SIntFunction)
+BOOST_TTI_HAS_FUNCTION(PublicIntFunction)
+BOOST_TTI_HAS_FUNCTION(TSFunction)
+
+#endif // BOOST_TEST_HAS_FUNCTION_HPP
Added: trunk/libs/tti/test/test_has_fun_compile.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/tti/test/test_has_fun_compile.cpp	2012-12-17 23:19:59 EST (Mon, 17 Dec 2012)
@@ -0,0 +1,33 @@
+
+//  (C) Copyright Edward Diener 2012
+//  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_has_fun.hpp"
+#include <boost/mpl/assert.hpp>
+
+int main()
+  {
+  
+  // You can always instantiate without compiler errors
+  
+  TheTIntFunction<AType,void,boost::mpl::vector<long,double> > aVar;
+  BOOST_TTI_HAS_FUNCTION_GEN(someFunctionMember)<AnotherType,double,boost::mpl::vector<short,short,long,int> > aVar2;
+  Pickedname<AnotherType,AType,boost::mpl::vector<long,long> > aVar3;
+  
+  // Compile time asserts
+  
+  BOOST_MPL_ASSERT((TheTIntFunction<AnotherType,AType,boost::mpl::vector<long,double> >));
+  BOOST_MPL_ASSERT((BOOST_TTI_HAS_FUNCTION_GEN(VoidFunction)<AType,void>));
+  BOOST_MPL_ASSERT((FunctionReturningInt<AType,int>));
+  BOOST_MPL_ASSERT((FunctionReturningInt<AnotherType,double,boost::mpl::vector<int> >));
+  BOOST_MPL_ASSERT((BOOST_TTI_HAS_FUNCTION_GEN(TSFunction)<AnotherType,AType::AStructType,boost::mpl::vector<AType::AnIntType,double> >));
+  BOOST_MPL_ASSERT((BOOST_TTI_HAS_FUNCTION_GEN(aFunction)<AnotherType,AType,boost::mpl::vector<int> >));
+  BOOST_MPL_ASSERT((AnotherIntFunction<AnotherType,int,boost::mpl::vector<AType> >));
+  BOOST_MPL_ASSERT((HaveTheSIntFunction<AType,int,boost::mpl::vector<long,double> >));
+  BOOST_MPL_ASSERT((BOOST_TTI_HAS_FUNCTION_GEN(sFunction)<AnotherType,AType::AnIntType,boost::mpl::vector<int,long,double> >));
+  
+  return 0;
+
+  }
Added: trunk/libs/tti/test/test_has_fun_fail.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/tti/test/test_has_fun_fail.cpp	2012-12-17 23:19:59 EST (Mon, 17 Dec 2012)
@@ -0,0 +1,19 @@
+
+//  (C) Copyright Edward Diener 2012
+//  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_has_fun.hpp"
+#include <boost/mpl/assert.hpp>
+
+int main()
+  {
+  
+  // Wrong function signature for sFunction
+  
+  BOOST_MPL_ASSERT((BOOST_TTI_HAS_FUNCTION_GEN(sFunction)<AnotherType,AType::AnIntType,boost::mpl::vector<short,long,double> >));
+  
+  return 0;
+
+  }
Added: trunk/libs/tti/test/test_has_fun_fail2.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/tti/test/test_has_fun_fail2.cpp	2012-12-17 23:19:59 EST (Mon, 17 Dec 2012)
@@ -0,0 +1,18 @@
+
+//  (C) Copyright Edward Diener 2012
+//  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_has_fun.hpp"
+
+int main()
+  {
+  
+  // Function signature has type which does not exist
+  
+  BOOST_TTI_HAS_FUNCTION_GEN(sFunction)<NVType,AType::AnIntType,boost::mpl::vector<short,long,double> > aVar;
+  
+  return 0;
+
+  }
Added: trunk/libs/tti/test/test_has_fun_fail3.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/tti/test/test_has_fun_fail3.cpp	2012-12-17 23:19:59 EST (Mon, 17 Dec 2012)
@@ -0,0 +1,19 @@
+
+//  (C) Copyright Edward Diener 2012
+//  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_has_fun.hpp"
+#include <boost/mpl/assert.hpp>
+
+int main()
+  {
+  
+  // Wrong function signature for SIntFunction
+  
+  BOOST_MPL_ASSERT((HaveTheSIntFunction<AType,int,boost::mpl::vector<float,double> >));
+  
+  return 0;
+
+  }
Added: trunk/libs/tti/test/test_has_fun_fail4.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/tti/test/test_has_fun_fail4.cpp	2012-12-17 23:19:59 EST (Mon, 17 Dec 2012)
@@ -0,0 +1,18 @@
+
+//  (C) Copyright Edward Diener 2012
+//  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_has_fun.hpp"
+
+int main()
+  {
+  
+  // Function signature has type which does not exist
+  
+  BOOST_TTI_HAS_FUNCTION_GEN(TSFunction)<AnotherType,AType::AClassType,boost::mpl::vector<AType::AnIntType,double> > aVar;
+  
+  return 0;
+
+  }