Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r49472 - in sandbox/guigl: boost/parameter boost/parameter/aux_ libs/guigl/build/xcodeide/guigl.xcodeproj libs/guigl/example libs/guigl/test
From: stipe_at_[hidden]
Date: 2008-10-28 01:21:10


Author: srajko
Date: 2008-10-28 01:21:08 EDT (Tue, 28 Oct 2008)
New Revision: 49472
URL: http://svn.boost.org/trac/boost/changeset/49472

Log:
added delayed construction for keyword call operator
Added:
   sandbox/guigl/boost/parameter/aux_/delayed_constructor.hpp (contents, props changed)
   sandbox/guigl/libs/guigl/test/test_delayed_constructor.cpp (contents, props changed)
Text files modified:
   sandbox/guigl/boost/parameter/aux_/typed_arg_list.hpp | 2 ++
   sandbox/guigl/boost/parameter/aux_/typed_tagged_argument.hpp | 20 ++++++++++++++------
   sandbox/guigl/boost/parameter/typed_keyword.hpp | 13 +++++++------
   sandbox/guigl/libs/guigl/build/xcodeide/guigl.xcodeproj/project.pbxproj | 4 ++++
   sandbox/guigl/libs/guigl/example/window_example.cpp | 16 ++++++++--------
   sandbox/guigl/libs/guigl/test/Jamfile | 1 +
   6 files changed, 36 insertions(+), 20 deletions(-)

Added: sandbox/guigl/boost/parameter/aux_/delayed_constructor.hpp
==============================================================================
--- (empty file)
+++ sandbox/guigl/boost/parameter/aux_/delayed_constructor.hpp 2008-10-28 01:21:08 EDT (Tue, 28 Oct 2008)
@@ -0,0 +1,90 @@
+/*=============================================================================
+ Copyright (c) 2007 Tobias Schwinger
+ Copyright 2008 Stjepan Rajko
+
+ 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).
+==============================================================================*/
+
+#ifndef BOOST__PARAMETER__AUX__DELAYED_CONSTRUCTOR_HPP
+# ifndef BOOST_PP_IS_ITERATING
+
+#include <boost/preprocessor/iteration/iterate.hpp>
+#include <boost/preprocessor/repetition/enum.hpp>
+#include <boost/preprocessor/repetition/enum_params.hpp>
+#include <boost/preprocessor/repetition/enum_params_with_a_default.hpp>
+#include <boost/preprocessor/repetition/enum_binary_params.hpp>
+
+#include <boost/mpl/bool.hpp>
+
+#define BOOST_PARAMETER_MAX_DELAYED_CONSTRUCTOR_ARITY 3
+
+namespace boost { namespace parameter { namespace aux {
+
+ struct void_;
+
+ template<typename T>
+ struct is_delayed_constructor
+ : public mpl::false_
+ {};
+
+ template< typename T, BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(BOOST_PP_INC(BOOST_PARAMETER_MAX_DELAYED_CONSTRUCTOR_ARITY), typename T, void_) >
+ struct delayed_constructor;
+
+ template< typename T, BOOST_PP_ENUM_PARAMS(BOOST_PARAMETER_MAX_DELAYED_CONSTRUCTOR_ARITY, typename T)>
+ struct is_delayed_constructor<delayed_constructor<T, BOOST_PP_ENUM_PARAMS(BOOST_PARAMETER_MAX_DELAYED_CONSTRUCTOR_ARITY, T)> >
+ : public mpl::true_
+ {};
+
+ template< typename T >
+ struct value_type_of
+ {};
+
+ template< typename T, BOOST_PP_ENUM_PARAMS(BOOST_PARAMETER_MAX_DELAYED_CONSTRUCTOR_ARITY, typename T)>
+ struct value_type_of<delayed_constructor<T, BOOST_PP_ENUM_PARAMS(BOOST_PARAMETER_MAX_DELAYED_CONSTRUCTOR_ARITY, T)> >
+ {
+ typedef typename delayed_constructor<T, BOOST_PP_ENUM_PARAMS(BOOST_PARAMETER_MAX_DELAYED_CONSTRUCTOR_ARITY, T)>::value_type type;
+ };
+
+# define BOOST_PP_FILENAME_1 <boost/parameter/aux_/delayed_constructor.hpp>
+# define BOOST_PP_ITERATION_LIMITS (1,BOOST_PARAMETER_MAX_DELAYED_CONSTRUCTOR_ARITY)
+# include BOOST_PP_ITERATE()
+
+} } }
+
+# define BOOST__PARAMETER__AUX__DELAYED_CONSTRUCTOR_HPP
+# else // defined(BOOST_PP_IS_ITERATING)
+# define N BOOST_PP_ITERATION()
+ template< typename T, BOOST_PP_ENUM_PARAMS(N, typename T) >
+ struct delayed_constructor< T, BOOST_PP_ENUM_PARAMS(N, T) >
+ {
+ typedef T value_type;
+
+ delayed_constructor(const delayed_constructor &rhs)
+# define TEMP_INIT(z,n,text) t ## n (rhs.t ## n)
+ : BOOST_PP_ENUM(N, TEMP_INIT, _)
+# undef TEMP_INIT
+ {}
+
+ delayed_constructor(BOOST_PP_ENUM_BINARY_PARAMS(N,const T,& a))
+# define TEMP_INIT(z,n,text) t ## n (a ## n)
+ : BOOST_PP_ENUM(N, TEMP_INIT, _)
+# undef TEMP_INIT
+ {}
+
+ operator T() const
+ {
+ return T(BOOST_PP_ENUM_PARAMS(N, t));
+ }
+
+# define TEMP_DECL(z,n,text) const T ## n & t ## n;
+ BOOST_PP_REPEAT(N, TEMP_DECL, _)
+# undef TEMP_DECL
+ };
+
+# undef N
+# endif // defined(BOOST_PP_IS_ITERATING)
+
+#endif // include guard
+

Modified: sandbox/guigl/boost/parameter/aux_/typed_arg_list.hpp
==============================================================================
--- sandbox/guigl/boost/parameter/aux_/typed_arg_list.hpp (original)
+++ sandbox/guigl/boost/parameter/aux_/typed_arg_list.hpp 2008-10-28 01:21:08 EDT (Tue, 28 Oct 2008)
@@ -190,6 +190,8 @@
       , get_reference<TaggedArg>
>::type reference;
 
+ typedef typename TaggedArg::index_result_type index_result_type;
+
     typedef typename mpl::if_<
         holds_maybe
       , reference

Modified: sandbox/guigl/boost/parameter/aux_/typed_tagged_argument.hpp
==============================================================================
--- sandbox/guigl/boost/parameter/aux_/typed_tagged_argument.hpp (original)
+++ sandbox/guigl/boost/parameter/aux_/typed_tagged_argument.hpp 2008-10-28 01:21:08 EDT (Tue, 28 Oct 2008)
@@ -14,9 +14,12 @@
 # include <boost/parameter/aux_/typed_arg_list.hpp>
 # include <boost/parameter/aux_/result_of0.hpp>
 # include <boost/parameter/aux_/tagged_argument.hpp>
+# include <boost/parameter/aux_/delayed_constructor.hpp>
 # include <boost/mpl/if.hpp>
+# include <boost/mpl/eval_if.hpp>
 # include <boost/mpl/apply_wrap.hpp>
 # include <boost/mpl/and.hpp>
+# include <boost/mpl/identity.hpp>
 # include <boost/mpl/not.hpp>
 # include <boost/type_traits/is_same.hpp>
 # include <boost/type_traits/is_convertible.hpp>
@@ -36,8 +39,13 @@
 struct typed_tagged_argument : tagged_argument_base
 {
     typedef Keyword key_type;
- typedef Arg value_type;
- typedef Arg& reference;
+ typedef Arg arg_type;
+
+ typedef typename mpl::eval_if<is_delayed_constructor<Arg>, value_type_of<Arg>, mpl::identity<Arg> >::type value_type;
+ typedef value_type& reference;
+
+ typedef typename mpl::if_<is_delayed_constructor<Arg>, value_type, reference>::type index_result_type;
+ typedef typename mpl::if_<is_delayed_constructor<Arg>, Arg, reference>::type storage_type;
 
     typed_tagged_argument(reference x) : value(x) {}
 
@@ -84,7 +92,7 @@
         return Tag::default_value();
     }
 
- reference operator[](keyword_base<Keyword> const&) const
+ index_result_type operator[](keyword_base<Keyword> const&) const
     {
         return value;
     }
@@ -95,13 +103,13 @@
     }*/
 
     template <class Default>
- reference operator[](default_<key_type,Default> const& x) const
+ index_result_type operator[](default_<key_type,Default> const& x) const
     {
         return value;
     }
 
     template <class F>
- reference operator[](lazy_default<key_type,F> const& x) const
+ index_result_type operator[](lazy_default<key_type,F> const& x) const
     {
         return value;
     }
@@ -128,7 +136,7 @@
         parameter_requirements<key_type,Predicate,HasDefault>*
     );
 
- reference value;
+ storage_type value;
 
     // MPL sequence support
     typedef typed_tagged_argument type; // Convenience for users

Modified: sandbox/guigl/boost/parameter/typed_keyword.hpp
==============================================================================
--- sandbox/guigl/boost/parameter/typed_keyword.hpp (original)
+++ sandbox/guigl/boost/parameter/typed_keyword.hpp 2008-10-28 01:21:08 EDT (Tue, 28 Oct 2008)
@@ -33,6 +33,7 @@
 struct typed_keyword : public keyword_base<Tag>
 {
     typedef aux::typed_tagged_argument<Tag, typename Tag::value_type> typed_tagged_argument_type;
+ typedef typename Tag::value_type value_type;
     
     typed_tagged_argument_type const
     operator=(typename Tag::value_type& x) const
@@ -41,19 +42,19 @@
     }
     
     template<typename T0>
- typed_tagged_argument_type const
+ aux::typed_tagged_argument<Tag, const aux::delayed_constructor<value_type, T0> > const
     operator()(const T0 &t0) const
- { return typed_tagged_argument_type(typename Tag::value_type(t0)); }
+ { return aux::typed_tagged_argument<Tag, const aux::delayed_constructor<value_type, T0> >(aux::delayed_constructor<value_type, T0>(t0)); }
 
     template<typename T0, typename T1>
- typed_tagged_argument_type const
+ aux::typed_tagged_argument<Tag, const aux::delayed_constructor<value_type, T0, T1> > const
     operator()(const T0 &t0, const T1 &t1) const
- { return typed_tagged_argument_type(typename Tag::value_type(t0, t1)); }
+ { return aux::typed_tagged_argument<Tag, const aux::delayed_constructor<value_type, T0, T1> >(aux::delayed_constructor<value_type, T0, T1>(t0, t1)); }
 
     template<typename T0, typename T1, typename T2>
- typed_tagged_argument_type const
+ aux::typed_tagged_argument<Tag, const aux::delayed_constructor<value_type, T0, T1, T2> > const
     operator()(const T0 &t0, const T1 &t1, const T2 &t2) const
- { return typed_tagged_argument_type(typename Tag::value_type(t0, t1, t2)); }
+ { return aux::typed_tagged_argument<Tag, const aux::delayed_constructor<value_type, T0, T1, T2> >(aux::delayed_constructor<value_type, T0, T1, T2>(t0, t1, t2)); }
     
  public: // Insurance against ODR violations
     

Modified: sandbox/guigl/libs/guigl/build/xcodeide/guigl.xcodeproj/project.pbxproj
==============================================================================
--- sandbox/guigl/libs/guigl/build/xcodeide/guigl.xcodeproj/project.pbxproj (original)
+++ sandbox/guigl/libs/guigl/build/xcodeide/guigl.xcodeproj/project.pbxproj 2008-10-28 01:21:08 EDT (Tue, 28 Oct 2008)
@@ -161,6 +161,8 @@
                 08AD8F620E5CD63400BFB2C8 /* opengl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = opengl.hpp; sourceTree = "<group>"; };
                 08ADC1F90E7B62BD00D8CB9D /* static_compound.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = static_compound.hpp; sourceTree = "<group>"; };
                 08ADC1FD0E7B64E100D8CB9D /* static_compound.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = static_compound.hpp; sourceTree = "<group>"; };
+ 08B919780EB682BC00F743E3 /* delayed_constructor.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = delayed_constructor.hpp; sourceTree = "<group>"; };
+ 08B9197C0EB6885C00F743E3 /* test_delayed_constructor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = test_delayed_constructor.cpp; sourceTree = "<group>"; };
                 08D0F2550E6712E90026C6DF /* active_colored.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = active_colored.hpp; sourceTree = "<group>"; };
                 08D0F25D0E67139E0026C6DF /* active_colored.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = active_colored.hpp; sourceTree = "<group>"; };
                 08D5606D0E52901F005A2391 /* window.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = window.cpp; sourceTree = "<group>"; };
@@ -373,6 +375,7 @@
                                 089D83780E5A3AA900325868 /* test_parameter_map_compilation.cpp */,
                                 0885D46A0E539F7000DFFA5D /* test_parameter_dispatch_compilation.cpp */,
                                 089E86720E5A80E500DA4902 /* test_parameter.cpp */,
+ 08B9197C0EB6885C00F743E3 /* test_delayed_constructor.cpp */,
                         );
                         name = test;
                         path = ../../test;
@@ -408,6 +411,7 @@
                         children = (
                                 08F506AF0E5B42930020D95E /* typed_arg_list.hpp */,
                                 08F506AB0E5B41AD0020D95E /* typed_tagged_argument.hpp */,
+ 08B919780EB682BC00F743E3 /* delayed_constructor.hpp */,
                         );
                         path = aux_;
                         sourceTree = "<group>";

Modified: sandbox/guigl/libs/guigl/example/window_example.cpp
==============================================================================
--- sandbox/guigl/libs/guigl/example/window_example.cpp (original)
+++ sandbox/guigl/libs/guigl/example/window_example.cpp 2008-10-28 01:21:08 EDT (Tue, 28 Oct 2008)
@@ -56,19 +56,19 @@
 
     widget::labeled_button *b1 = new widget::labeled_button((
         _size=size_type(100,30),
- _position=position_type(50, 50),
- _background=color_type(1,1,1),
- _active_color=color_type(1,0,0),
- _color=color_type(0,0,0),
+ _position(50, 50),
+ _background(1,1,1),
+ _active_color(1,0,0),
+ _color(0,0,0),
         _label="Button"));
     test_window1 << b1;
     
     widget::labeled_slider *s = new widget::labeled_slider((
         _label="Slider",
- _size(100,30),
- _position(50,80),
- _background(0.5,0.5,0.5),
- _active_color(0,1,0),
+ _size=size_type(100,30),
+ _position=position_type(50,80),
+ _background=color_type(0.5,0.5,0.5),
+ _active_color=color_type(0,1,0),
         _min=0.1,_max=0.9,_value=0.5,
         _step=0.1 ));
     test_window1 << s;

Modified: sandbox/guigl/libs/guigl/test/Jamfile
==============================================================================
--- sandbox/guigl/libs/guigl/test/Jamfile (original)
+++ sandbox/guigl/libs/guigl/test/Jamfile 2008-10-28 01:21:08 EDT (Tue, 28 Oct 2008)
@@ -16,3 +16,4 @@
     ;
 
 run test_parameter.cpp ;
+run test_delayed_constructor.cpp ;

Added: sandbox/guigl/libs/guigl/test/test_delayed_constructor.cpp
==============================================================================
--- (empty file)
+++ sandbox/guigl/libs/guigl/test/test_delayed_constructor.cpp 2008-10-28 01:21:08 EDT (Tue, 28 Oct 2008)
@@ -0,0 +1,32 @@
+/*=================================---------------------------------------------
+ Copyright 2007,2008 Stjepan Rajko
+
+ 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)
+-----------------------------------------------===============================*/
+
+
+#include <boost/parameter/aux_/delayed_constructor.hpp>
+#include <utility>
+
+#define BOOST_TEST_MAIN
+#include <boost/test/unit_test.hpp>
+
+BOOST_AUTO_TEST_CASE( test )
+{
+ using namespace boost::parameter::aux;
+
+ delayed_constructor<int, int> delayed_int(2);
+ int i = delayed_int;
+
+ BOOST_CHECK_EQUAL(i, 2);
+
+
+ delayed_constructor<std::pair<int, double>, int, double> delayed(1, 3.5);
+
+ std::pair<int, double> p = delayed;
+
+ BOOST_CHECK_EQUAL(p.first, 1);
+ BOOST_CHECK_EQUAL(p.second, 3.5);
+}
\ No newline at end of file


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