|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r52842 - sandbox/ftmpl
From: whatwasthataddress_at_[hidden]
Date: 2009-05-07 19:38:19
Author: tzlaine
Date: 2009-05-07 19:38:17 EDT (Thu, 07 May 2009)
New Revision: 52842
URL: http://svn.boost.org/trac/boost/changeset/52842
Log:
Initial checkin of FTMPL.
Added:
sandbox/ftmpl/alias.hpp (contents, props changed)
sandbox/ftmpl/apply.hpp (contents, props changed)
sandbox/ftmpl/fold.hpp (contents, props changed)
sandbox/ftmpl/is_same.hpp (contents, props changed)
sandbox/ftmpl/list.hpp (contents, props changed)
sandbox/ftmpl/quote.hpp (contents, props changed)
sandbox/ftmpl/size_t.hpp (contents, props changed)
sandbox/ftmpl/type.hpp (contents, props changed)
sandbox/ftmpl/unwrap.hpp (contents, props changed)
sandbox/ftmpl/value.hpp (contents, props changed)
sandbox/ftmpl/vector.hpp (contents, props changed)
Added: sandbox/ftmpl/alias.hpp
==============================================================================
--- (empty file)
+++ sandbox/ftmpl/alias.hpp 2009-05-07 19:38:17 EDT (Thu, 07 May 2009)
@@ -0,0 +1,11 @@
+#ifndef BOOST_FTMPL_ALIAS_HPP
+#define BOOST_FTMPL_ALIAS_HPP
+
+// ToDo: Remove typeof requirement
+#define BOOST_FTMPL_TYPE_ALIAS( name, expr ) \
+typedef decltype( expr ) name;
+
+#define BOOST_FTMPL_FUN_ALIAS( name, expr ) \
+static decltype( expr ) name();
+
+#endif // BOOST_FTMPL_ALIAS_HPP
Added: sandbox/ftmpl/apply.hpp
==============================================================================
--- (empty file)
+++ sandbox/ftmpl/apply.hpp 2009-05-07 19:38:17 EDT (Thu, 07 May 2009)
@@ -0,0 +1,15 @@
+#ifndef BOOST_FTMPL_APPLY_HPP
+#define BOOST_FTMPL_APPLY_HPP
+
+#include "type.hpp"
+
+namespace boost { namespace ftmpl {
+
+// ToDo: Possibly remove this file and definition
+template< typename Metafun, typename ... Args >
+auto apply( type_t< Metafun >&, Args& ... args )
+-> decltype( Metafun()( args... ) );
+
+} }
+
+#endif // BOOST_FTMPL_APPLY_HPP
Added: sandbox/ftmpl/fold.hpp
==============================================================================
--- (empty file)
+++ sandbox/ftmpl/fold.hpp 2009-05-07 19:38:17 EDT (Thu, 07 May 2009)
@@ -0,0 +1,19 @@
+#ifndef BOOST_FTMPL_FOLD_HPP
+#define BOOST_FTMPL_FOLD_HPP
+
+#include "vector.hpp"
+#include "type.hpp"
+#include "is_same.hpp"
+
+namespace boost { namespace ftmpl {
+
+template< typename Fn, typename State >
+State& fold( Fn&, State&, type_t< vector_t<> >& );
+
+template< typename Fn, typename State, typename Head, typename ... Tail >
+auto fold( type_t< Fn >&, State&, type_t< vector_t< Head, Tail... > >& )
+-> decltype( fold( type< Fn >(), Fn()( type< State >(), type< Head >() ), vector< Tail... >() ) );
+
+} }
+
+#endif // BOOST_FTMPL_FOLD_HPP
Added: sandbox/ftmpl/is_same.hpp
==============================================================================
--- (empty file)
+++ sandbox/ftmpl/is_same.hpp 2009-05-07 19:38:17 EDT (Thu, 07 May 2009)
@@ -0,0 +1,22 @@
+#ifndef BOOST_FTMPL_IS_SAME_HPP
+#define BOOST_FTMPL_IS_SAME_HPP
+
+#include "value.hpp"
+#include "type.hpp"
+
+namespace boost { namespace ftmpl {
+
+struct is_same_t
+{
+ template< typename L, typename R >
+ type_t< false_t >& operator ()( L&, R& );
+
+ template< typename L >
+ type_t< true_t >& operator()( L&, L& );
+};
+
+extern type_t< is_same_t >& is_same;
+
+} }
+
+#endif // BOOST_FTMPL_IS_SAME_HPP
Added: sandbox/ftmpl/list.hpp
==============================================================================
--- (empty file)
+++ sandbox/ftmpl/list.hpp 2009-05-07 19:38:17 EDT (Thu, 07 May 2009)
@@ -0,0 +1,33 @@
+#ifndef BOOST_FTMPL_LIST_HPP
+#define BOOST_FTMPL_LIST_HPP
+
+namespace boost { namespace ftmpl {
+
+namespace detail {
+
+class list_end;
+
+}
+
+template< typename Head, typename Tail = detail::list_end >
+struct list_t;
+
+template< typename Head, typename Tail >
+list_t< Head, Tail >& list();
+
+template< typename Head >
+list_t< Head >& list();
+
+template< typename Head, typename Tail, typename NewFront >
+list_t< NewFront, list_t< Head, Tail > >&
+push_front( list_t< Head, Tail >&, NewFront& );
+
+template< typename Head, typename TailContents >
+list_t< TailContents >& pop_front( list_t< Head, list_t< TailContents >& );
+
+template< typename Head, typename Tail >
+Head& front( list_t< Head, Tail >& );
+
+} }
+
+#endif
Added: sandbox/ftmpl/quote.hpp
==============================================================================
--- (empty file)
+++ sandbox/ftmpl/quote.hpp 2009-05-07 19:38:17 EDT (Thu, 07 May 2009)
@@ -0,0 +1,19 @@
+#ifndef BOOST_FTMPL_QUOTE_HPP
+#define BOOST_FTMPL_QUOTE_HPP
+
+namespace boost { namespace ftmpl {
+#if 0
+template< template< typename ... > class Metafun >
+struct quote_t;
+
+template< template< typename ... > class Metafun >
+quote_t< Metafun >& quote();
+
+template< template< typename ... > class Metafun, typename ... Arg >
+auto apply_t( quote_t< Metafun >& quo, Arg arg ... )
+-> decltype( Metafun< Arg... >() );
+#endif
+
+} }
+
+#endif // BOOST_FTMPL_QUOTE_HPP
Added: sandbox/ftmpl/size_t.hpp
==============================================================================
--- (empty file)
+++ sandbox/ftmpl/size_t.hpp 2009-05-07 19:38:17 EDT (Thu, 07 May 2009)
@@ -0,0 +1,13 @@
+#ifndef BOOST_FTMPL_SIZE_T_HPP
+#define BOOST_FTMPL_SIZE_T_HPP
+
+#include <cstddef>
+#include "value.hpp"
+
+namespace boost { namespace ftmpl {
+
+BOOST_FTMPL_VALUE_DEF( size_t, ::std::size_t )
+
+} }
+
+#endif // BOOST_FTMPL_SIZE_T_HPP
Added: sandbox/ftmpl/type.hpp
==============================================================================
--- (empty file)
+++ sandbox/ftmpl/type.hpp 2009-05-07 19:38:17 EDT (Thu, 07 May 2009)
@@ -0,0 +1,30 @@
+#ifndef BOOST_FTMPL_TYPE_HPP
+#define BOOST_FTMPL_TYPE_HPP
+
+namespace boost { namespace ftmpl {
+
+template< typename T >
+struct type_t;
+
+template< typename T >
+type_t< T >& type();
+
+template< typename T >
+type_t< T >& type( T& );
+
+template< typename T >
+type_t< T >& type( type_t< T >& );
+
+template< typename T >
+struct unwrap;
+
+template< typename T >
+struct unwrap< type_t< T >& >
+{
+ typedef T type;
+};
+
+} }
+
+
+#endif // BOOST_FTMPL_TYPE_HPP
Added: sandbox/ftmpl/unwrap.hpp
==============================================================================
--- (empty file)
+++ sandbox/ftmpl/unwrap.hpp 2009-05-07 19:38:17 EDT (Thu, 07 May 2009)
@@ -0,0 +1,39 @@
+#ifndef BOOST_FTMPL_UNWRAP_HPP
+#define BOOST_FTMPL_UNWRAP_HPP
+
+namespace boost { namespace ftmpl {
+
+template< typename T >
+struct unwrap;
+
+template< typename T >
+struct unwrap< T& >
+{
+ typedef T type;
+};
+
+#ifdef BOOST_HAS_RELAXED_TYPENAME
+
+#define BOOST_FTMPL_UNWRAP( expr ) \
+typename ::boost::ftmpl::unwrap< decltype( expr ) >::type
+
+#else
+
+#define BOOST_FTMPL_UNWRAP( expr ) \
+::boost::ftmpl::unwrap< decltype( ( expr ) ) >::type
+
+#endif
+
+#define BOOST_FTMPL_UNWRAP_T( expr ) \
+typename ::boost::ftmpl::unwrap< decltype( ( expr ) ) >::type
+
+
+template< typename T >
+struct unwrap_value;
+
+#define BOOST_FTMPL_UNWRAP_VALUE( expr ) \
+::boost::ftmpl::unwrap_value< decltype( expr ) >::value
+
+} }
+
+#endif // BOOST_FTMPL_UNWRAP_HPP
Added: sandbox/ftmpl/value.hpp
==============================================================================
--- (empty file)
+++ sandbox/ftmpl/value.hpp 2009-05-07 19:38:17 EDT (Thu, 07 May 2009)
@@ -0,0 +1,109 @@
+#ifndef BOOST_FTMPL_VALUE_HPP
+#define BOOST_FTMPL_VALUE_HPP
+
+#include "type.hpp"
+
+namespace boost { namespace ftmpl {
+
+template< typename T, T Value >
+struct value_t;
+
+template< typename T, T Value >
+value_t< T, Value >& value();
+
+#ifdef BOOST_HAS_TEMPLATE_ALIASES
+
+#define BOOST_FTMPL_VALUE_ALIAS( name, type ) \
+template< type Value > \
+using name ## _ ## t = value_t< type, Value >;
+
+#else
+
+#define BOOST_FTMPL_VALUE_ALIAS( name, type ) /**/
+
+#endif
+
+#define BOOST_FTMPL_VALUE_DEF( name, type ) \
+BOOST_FTMPL_VALUE_ALIAS( name, type ) \
+template< type Value > \
+value_t< type, Value >& name();
+
+BOOST_FTMPL_VALUE_DEF( bool_, bool )
+BOOST_FTMPL_VALUE_DEF( char_, char )
+BOOST_FTMPL_VALUE_DEF( short_, short )
+BOOST_FTMPL_VALUE_DEF( int_, int )
+BOOST_FTMPL_VALUE_DEF( long_, long )
+BOOST_FTMPL_VALUE_DEF( wchar_t_, wchar_t )
+BOOST_FTMPL_VALUE_DEF( schar, signed char )
+BOOST_FTMPL_VALUE_DEF( uchar, unsigned char )
+BOOST_FTMPL_VALUE_DEF( ushort, unsigned short )
+BOOST_FTMPL_VALUE_DEF( uint, unsigned int )
+BOOST_FTMPL_VALUE_DEF( ulong, unsigned long )
+BOOST_FTMPL_VALUE_DEF( longlong, long long )
+BOOST_FTMPL_VALUE_DEF( ulonglong, unsigned long long )
+
+// ToDo: Account for integral promotion
+#define MPL_UNARY_OP( op ) \
+template< typename Type, Type Value > \
+type_t< value_t< Type, ( op Value ) > >& \
+operator op( type_t< value_t< Type, Value > >& );
+
+MPL_UNARY_OP( + )
+MPL_UNARY_OP( - )
+MPL_UNARY_OP( ! )
+MPL_UNARY_OP( ~ )
+
+// ToDo: Account for integral promotion
+// Hack: Don't use LType
+#define MPL_BINARY_OP( op ) \
+template< typename LType, LType LValue, typename RType, RType RValue > \
+type_t< value_t< LType, ( LValue op RValue ) > >& \
+operator op( type_t< value_t< LType, LValue > >&, type_t< value_t< RType, RValue > >& );
+
+MPL_BINARY_OP( + )
+MPL_BINARY_OP( - )
+MPL_BINARY_OP( * )
+MPL_BINARY_OP( / )
+MPL_BINARY_OP( ^ )
+MPL_BINARY_OP( | )
+MPL_BINARY_OP( & )
+MPL_BINARY_OP( << )
+MPL_BINARY_OP( >> )
+
+#define MPL_BOOL_BINARY_OP( op ) \
+template< typename LType, LType LValue, typename RType, RType RValue > \
+type_t< value_t< bool, ( LValue op RValue ) > >& \
+operator op( type_t< value_t< LType, LValue > >&, type_t< value_t< RType, RValue > >& );
+
+MPL_BOOL_BINARY_OP( || )
+MPL_BOOL_BINARY_OP( && )
+MPL_BOOL_BINARY_OP( < )
+MPL_BOOL_BINARY_OP( > )
+MPL_BOOL_BINARY_OP( <= )
+MPL_BOOL_BINARY_OP( >= )
+MPL_BOOL_BINARY_OP( == )
+MPL_BOOL_BINARY_OP( != )
+
+typedef value_t< bool, true > true_t;
+typedef value_t< bool, false > false_t;
+
+type_t< true_t >& true_();
+type_t< false_t >& false_();
+
+template< typename T, T V >
+type_t< T > value_type( type_t< value_t< T, V > >& );
+
+template< typename T >
+struct unwrap_value;
+
+template< typename T, T V >
+struct unwrap_value< type_t< value_t< T, V > > >
+{
+ static T const value = V;
+};
+
+//#define BOOST_FTMPL_
+
+} }
+
+#endif // BOOST_FTMPL_VALUE_HPP
Added: sandbox/ftmpl/vector.hpp
==============================================================================
--- (empty file)
+++ sandbox/ftmpl/vector.hpp 2009-05-07 19:38:17 EDT (Thu, 07 May 2009)
@@ -0,0 +1,38 @@
+#ifndef BOOST_FTMPL_VECTOR_HPP
+#define BOOST_FTMPL_VECTOR_HPP
+
+#include "size_t.hpp"
+#include "type.hpp"
+
+namespace boost { namespace ftmpl {
+
+template< typename ... T >
+struct vector_t;
+
+template< typename ... T >
+type_t< vector_t< T... > >& vector();
+
+template< typename ... T >
+type_t< vector_t< T... > >& vector( T& ... );
+
+template< typename ... T, typename Back >
+type_t< vector_t< T..., Back > >& push_back( type_t< vector_t< T... > >&, Back& );
+
+template< typename ... T, typename Last >
+type_t< vector_t< T... > >& pop_back( type_t< vector_t< T..., Last > >& );
+
+template< typename First, typename ... Tail >
+type_t< vector_t< Tail... > >& pop_front( type_t< vector_t< First, Tail... > >& );
+
+template< typename ... T, typename Tail >
+Tail& back( type_t< vector_t< T..., Tail > >& );
+
+template< typename Head, typename ... T >
+Head& front( type_t< vector_t< Head, T... > >& );
+
+template< typename ... T >
+type_t< value_t< ::std::size_t, sizeof...( T ) > >& size( type_t< vector_t< T... > >& );
+
+} }
+
+#endif
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk