├── .gitignore ├── Jamfile ├── Jamroot ├── LICENSE.md ├── README.md ├── TODO.md ├── boost-build.jam ├── boost └── proto │ └── v5 │ ├── accessors.hpp │ ├── action.hpp │ ├── action │ ├── and.hpp │ ├── apply.hpp │ ├── basic_action.hpp │ ├── block.hpp │ ├── call.hpp │ ├── case.hpp │ ├── env.hpp │ ├── eval.hpp │ ├── everything.hpp │ ├── everywhere.hpp │ ├── external.hpp │ ├── fold.hpp │ ├── if.hpp │ ├── integral_constant.hpp │ ├── let.hpp │ ├── make.hpp │ ├── match.hpp │ ├── matches.hpp │ ├── not.hpp │ ├── or.hpp │ ├── passthru.hpp │ ├── placeholders.hpp │ ├── protect.hpp │ ├── recursive_fold.hpp │ ├── string.hpp │ ├── switch.hpp │ ├── unpack.hpp │ └── void.hpp │ ├── children.hpp │ ├── core.hpp │ ├── custom.hpp │ ├── debug.hpp │ ├── deep_copy.hpp │ ├── def.hpp │ ├── detail │ ├── access.hpp │ ├── common_domain.hpp │ ├── compressed_pair.hpp │ └── operators.hpp │ ├── domain.hpp │ ├── env.hpp │ ├── expr.hpp │ ├── functional.hpp │ ├── functional │ ├── cxx.hpp │ ├── cxx │ │ ├── cast.hpp │ │ ├── construct.hpp │ │ ├── operators.hpp │ │ └── throw.hpp │ ├── fusion.hpp │ ├── fusion │ │ ├── at.hpp │ │ ├── pop_back.hpp │ │ ├── pop_front.hpp │ │ ├── push_back.hpp │ │ ├── push_front.hpp │ │ └── reverse.hpp │ ├── range.hpp │ ├── range │ │ ├── begin.hpp │ │ ├── empty.hpp │ │ ├── end.hpp │ │ ├── rbegin.hpp │ │ ├── rend.hpp │ │ └── size.hpp │ ├── std.hpp │ └── std │ │ ├── iterator.hpp │ │ └── utility.hpp │ ├── fusion.hpp │ ├── grammar.hpp │ ├── grammar │ ├── and.hpp │ ├── basic_grammar.hpp │ ├── case.hpp │ ├── expr.hpp │ ├── if.hpp │ ├── match.hpp │ ├── not.hpp │ ├── or.hpp │ ├── placeholders.hpp │ └── switch.hpp │ ├── literals.hpp │ ├── make_expr.hpp │ ├── matches.hpp │ ├── operators.hpp │ ├── placeholders.hpp │ ├── proto.hpp │ ├── proto_fwd.hpp │ ├── tags.hpp │ ├── unpack_expr.hpp │ ├── utility.hpp │ └── virtual_member.hpp └── libs └── proto └── v5 ├── example ├── Jamfile ├── lambda.cpp ├── map_list_of.cpp └── virtual_member.cpp ├── scratch ├── Jamfile ├── Makefile ├── main.cpp ├── proto-vc12.vcxproj ├── proto-vc12.vcxproj.filters ├── proto.sln ├── proto.vcxproj └── proto.vcxproj.filters └── test ├── Jamfile ├── action.cpp ├── apply.cpp ├── bug2407.cpp ├── common_domain.cpp ├── constrained_ops.cpp ├── cpp-next_bug.cpp ├── deep_copy.cpp ├── def.cpp ├── display_expr.cpp ├── everything.cpp ├── everywhere.cpp ├── expr.cpp ├── external.cpp ├── flatten.cpp ├── fold.cpp ├── let.cpp ├── logical_ops.cpp ├── make.cpp ├── make_expr.cpp ├── matches.cpp ├── mem_fun.cpp ├── mpl.cpp ├── noinvoke.cpp ├── pack_expansion.cpp ├── passthru.cpp ├── protect.cpp ├── unit_test.hpp └── virtual_member.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | *.suo 2 | *.vcxproj.user 3 | *.lastbuildstate 4 | *.o 5 | *.obj 6 | *.sdf 7 | *.opensdf 8 | *.exe 9 | ._* 10 | .\#* 11 | \#* 12 | .dir-locals.el 13 | bin/ 14 | libs/proto/v5/scratch/Debug/ 15 | -------------------------------------------------------------------------------- /Jamfile: -------------------------------------------------------------------------------- 1 | # Copyright Rene Rivera 2007. 2 | # 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # (See accompanying file LICENSE_1_0.txt or copy at 5 | # http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | # Usage: 8 | # 9 | # bjam [options | properties | targets] 10 | # 11 | # Options: 12 | # 13 | # --boost= The directotory of a Boost source tree. 14 | # Default; BOOST env var (if found) 15 | # Default; ../boost (if found) 16 | # 17 | # --boost-build= 18 | # The directory for the Boost.Build v2 files. 19 | # Default; BOOST_BUILD_PATH env var (if found) 20 | # Default; BOOST_BUILD env var (if found) 21 | # Default; /tools/build/v2 (if found) 22 | 23 | #~ If we have the Boost sources we can use the project... 24 | 25 | if [ GLOB $(BOOST) : [ modules.peek project : JAMFILE ] ] 26 | { 27 | use-project /boost : $(BOOST) ; 28 | } 29 | -------------------------------------------------------------------------------- /Jamroot: -------------------------------------------------------------------------------- 1 | # Copyright John Maddock 2010. 2 | # Copyright Eric Niebler 2012. 3 | # 4 | # Distributed under the Boost Software License, Version 1.0. 5 | # (See accompanying file LICENSE_1_0.txt or copy at 6 | # http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | import modules ; 9 | 10 | local boost = [ modules.peek : BOOST ] ; 11 | 12 | project proto 13 | : requirements . $(boost) 14 | : usage-requirements . $(boost) 15 | : build-dir bin 16 | ; 17 | 18 | # This seems to prevent some Boost.Build errors that otherwise occur :-( 19 | use-project /boost : $(boost) ; 20 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Proto-0x: A Reimagined EDSL Toolkit for C++-11 2 | ============================================== 3 | 4 | This project aims to reimplement and redesign [Boost.Proto](http://boost.org/libs/proto) for 5 | C++11. No effort will be made to preserve backwards compatibility with the C++98 version. 6 | 7 | This is highly experimental and undocumented code. You would be insane to use it for anything 8 | whatsoever. This code comes with no support. 9 | 10 | Pre-requisites 11 | -------------- 12 | 13 | This library depends on: 14 | 15 | * Clang 3.3 16 | * Boost >= 1.52 17 | -------------------------------------------------------------------------------- /TODO.md: -------------------------------------------------------------------------------- 1 | A Grab-Bag of Miscellaneous Thoughts 2 | ==================================== 3 | 4 | * Should `_(A(_left), B(_right))` be synonymous for `passthru(A, B)`? That would be consistent with the 5 | use of `_` in expression patterns like `_(A,B)`, where `_` means "any tag", but inconsistent with 6 | the use of `_` as a primitive transform, where `_(A,B)` simply returns `A`. 7 | 8 | * Each domain should have a post-process function object that takes and returns an expression. This 9 | is to replicate the generator functionality from Proto v4, where actions can be used to select 10 | between several wrapper types based on structural matching of the new expression. 11 | 12 | * Thoughts about `make(foo>())` 13 | + It doesn't invoke `some_action<>`. Should it? With what semantics? Is it right to be looking 14 | for a nested `::type` after substitution, or should it be checking for action-ness instead 15 | (or in addtion to)? What would that break? 16 | + Answer: it is technically not OK to test `some_action` for action-ness if there were 17 | no substitutions because it may not actually instantiate properly. See `careful` test in 18 | test/make.cpp 19 | 20 | * Proto v4 needs inline namespace also, and a macro-based solution for picking which namespace 21 | (v4 or v5) gets inlined. 22 | 23 | * Implement proper lexical scoping for `let` expressions. 24 | + Can the call action be modified to automatically create a proper lexical scope? 25 | 26 | * Think about basic actions. 27 | + Is the interface correct? 28 | + Do we really need actions to support an arbitrary number of arguments, when we only use 29 | the first three in practice? It needlessly complicates the action protocol. 30 | + Should the local variable scope be part of the environment, or should it be a 31 | fourth parameter? 32 | + Should *all* environment variables be part of a scope? Should we allow 33 | non-environments in the environments parameter as Proto-current does? 34 | 35 | * Everyplace where we directly return an rvalue reference is potentially creating a dangling 36 | reference. 37 | 38 | * Implementation of `unpack_expr` could probably use `fusion::invoke_function_object`. 39 | 40 | * Observation from Haskell land: `passthru` == `zipWith ($)` 41 | -------------------------------------------------------------------------------- /boost-build.jam: -------------------------------------------------------------------------------- 1 | # Copyright Rene Rivera 2007. 2 | # 3 | # Distributed under the Boost Software License, Version 1.0. 4 | # (See accompanying file LICENSE_1_0.txt or copy at 5 | # http://www.boost.org/LICENSE_1_0.txt) 6 | 7 | # For instructions see Jamfile.v2, or "bjam --help". 8 | 9 | local rule if-has-file ( file + : dir * ) 10 | { 11 | local result ; 12 | if $(dir) 13 | { 14 | result = [ GLOB $(dir) : $(file) ] ; 15 | } 16 | return $(result[1]:P) ; 17 | } 18 | 19 | #~ Attempts to find the Boost source tree... 20 | 21 | local boost-src = [ if-has-file LICENSE_1_0.txt : 22 | [ MATCH --boost=(.*) : $(ARGV) ] 23 | $(BOOST) 24 | $(BOOST_ROOT) 25 | $(.boost-build-file:D)/../boost 26 | $(.boost-build-file:D)/../Trunk 27 | ] ; 28 | 29 | # error handling: 30 | if ! $(boost-src) 31 | { 32 | ECHO Unable to find the Boost source tree in the locations searched. ; 33 | ECHO Try setting the environment variable BOOST to point to your ; 34 | ECHO Boost tree, or else invoke bjam with the --boost=path option. ; 35 | ECHO The Boost include path will not be automatically set. ; 36 | ECHO The paths searched were [ MATCH --boost=(.*) : $(ARGV) ] $(BOOST) $(.boost-build-file:D)/../boost $(.boost-build-file:D)/../Trunk ; 37 | ECHO But the file LICENSE_1_0.txt was not found in any of them ; 38 | } 39 | 40 | #~ Attempts to find the Boost.Build files... 41 | 42 | local boost-build-src = [ if-has-file bootstrap.jam : 43 | [ MATCH --boost-build=(.*) : $(ARGV) ] 44 | $(BOOST_BUILD_PATH) 45 | $(BOOST_BUILD) 46 | $(boost-src)/tools/build/v2 47 | ] ; 48 | 49 | # error handling: 50 | if ! $(boost-build-src) 51 | { 52 | ECHO Unable to find the Boost.Build source tree in the locations searched. ; 53 | ECHO Try setting the environment variable BOOST_BUILD to point to your ; 54 | ECHO Boost.Build tree, or else invoke bjam with the --boost-build=path option. ; 55 | ECHO The paths searched were [ MATCH --boost-build=(.*) : $(ARGV) ] $(BOOST_BUILD_PATH) $(BOOST_BUILD) $(boost-src)/tools/build/v2 ; 56 | ECHO But bootstrap.jam was not found in any of these ; 57 | ECHO More failures will very likely follow... ; 58 | } 59 | 60 | #~ Set some common vars to refer to the Boost sources... 61 | 62 | BOOST ?= $(boost-src) ; 63 | BOOST_ROOT ?= $(boost-src) ; 64 | 65 | #~ And load up Boost.Build... 66 | 67 | boost-build $(boost-build-src) ; 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /boost/proto/v5/action.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // action.hpp 3 | // Contains all Proto's build-in actions. 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_ACTION_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_ACTION_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /boost/proto/v5/action/and.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // and.hpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_PROTO_V5_ACTION_AND_HPP_INCLUDED 9 | #define BOOST_PROTO_V5_ACTION_AND_HPP_INCLUDED 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace boost 16 | { 17 | namespace proto 18 | { 19 | inline namespace v5 20 | { 21 | namespace detail 22 | { 23 | struct logical_and_ 24 | { 25 | template 26 | constexpr std::integral_constant(A::value) && static_cast(B::value)> 27 | operator()(A const &, B const &) const noexcept 28 | { 29 | return std::integral_constant(A::value) && static_cast(B::value)>(); 30 | } 31 | 32 | template(B::value)> 33 | inline constexpr bool operator()(bool a, B const &) const noexcept 34 | { 35 | return a && BV; 36 | } 37 | 38 | template(A::value)> 39 | inline constexpr bool operator()(A const &, bool b) const noexcept 40 | { 41 | return AV && b; 42 | } 43 | 44 | inline constexpr bool operator()(bool a, bool b) const noexcept 45 | { 46 | return a && b; 47 | } 48 | }; 49 | 50 | struct fold_and_ 51 | { 52 | static constexpr std::true_type call() noexcept 53 | { 54 | return std::true_type(); 55 | } 56 | 57 | template 58 | static constexpr auto call(BoolHead const &bh, BoolTail const &...bt) 59 | BOOST_PROTO_AUTO_RETURN( 60 | BOOST_PROTO_TRY_CALL(logical_and_())(bh, Impl::call(bt...)) 61 | ) 62 | }; 63 | 64 | template 65 | struct _and_ 66 | : basic_action<_and_> 67 | { 68 | template 69 | constexpr auto operator()(Args &&...args) const 70 | BOOST_PROTO_AUTO_RETURN( 71 | fold_and_::call(call_action_()(static_cast(args)...)...) 72 | ) 73 | }; 74 | } 75 | 76 | namespace extension 77 | { 78 | template 79 | struct action_impl 80 | : detail::_and_ 81 | {}; 82 | } 83 | } 84 | } 85 | } 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /boost/proto/v5/action/apply.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // apply.hpp 3 | // Treat the first argument as a callable and the others as arguments to the 4 | // callable 5 | // 6 | // Copyright 2012 Eric Niebler. Distributed under the Boost 7 | // Software License, Version 1.0. (See accompanying file 8 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | #ifndef BOOST_PROTO_V5_ACTION_APPLY_HPP_INCLUDED 11 | #define BOOST_PROTO_V5_ACTION_APPLY_HPP_INCLUDED 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace boost 20 | { 21 | namespace proto 22 | { 23 | inline namespace v5 24 | { 25 | namespace detail 26 | { 27 | template 28 | struct _apply 29 | : basic_action<_apply> 30 | { 31 | template 32 | constexpr auto operator()(Args &&... args) const 33 | BOOST_PROTO_AUTO_RETURN( 34 | BOOST_PROTO_TRY_CALL(detail::call_1_())( 35 | call_action_()(static_cast(args)...) 36 | , static_cast(args)... 37 | ) 38 | ) 39 | }; 40 | } 41 | 42 | struct apply 43 | {}; 44 | 45 | namespace extension 46 | { 47 | template 48 | struct action_impl 49 | : detail::_apply 50 | {}; 51 | } 52 | } 53 | } 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /boost/proto/v5/action/block.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // block.hpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_PROTO_V5_ACTION_BLOCK_HPP_INCLUDED 9 | #define BOOST_PROTO_V5_ACTION_BLOCK_HPP_INCLUDED 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace boost 17 | { 18 | namespace proto 19 | { 20 | inline namespace v5 21 | { 22 | /// \brief For matching all of a set of grammars. When used as a 23 | /// basic_action, \c and_\<\> applies the actions associated with 24 | /// the each grammar in the set, and returns the result of the last. 25 | /// 26 | /// An expression type \c E matches and_\ if \c E 27 | /// matches all \c Bx for \c x in [0,n). 28 | /// 29 | /// When applying and_\ as a basic_action with an 30 | /// expression \c e, state \c s and data \c d, it is 31 | /// equivalent to (B0()(e, s, d),B1()(e, s, d),...Bn()(e, s, d)). 32 | namespace detail 33 | { 34 | template 35 | struct _block 36 | : basic_action<_block> 37 | { 38 | template 39 | constexpr auto operator()(Args &&... args) const 40 | BOOST_PROTO_AUTO_RETURN( 41 | BOOST_PROTO_TRY_CALL(utility::functional::back())( 42 | (call_action_()(static_cast(args)...), utility::void_)... 43 | ) 44 | ) 45 | }; 46 | } 47 | 48 | struct block 49 | {}; 50 | 51 | namespace extension 52 | { 53 | template 54 | struct action_impl 55 | : detail::_block 56 | {}; 57 | } 58 | } 59 | } 60 | } 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /boost/proto/v5/action/case.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // case.hpp 3 | // Associate a custom basic_action with a grammar rule 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_ACTION_CASE_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_ACTION_CASE_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace boost 17 | { 18 | namespace proto 19 | { 20 | inline namespace v5 21 | { 22 | namespace extension 23 | { 24 | //////////////////////////////////////////////////////////////////////////////////// 25 | // case_ 26 | template 27 | struct action_impl 28 | : detail::_block 29 | {}; 30 | 31 | template 32 | struct action_impl 33 | : detail::as_action_ 34 | {}; 35 | 36 | // These two are defined in passthru.hpp 37 | template 38 | struct action_impl; 39 | 40 | template 41 | struct action_impl; 42 | 43 | //////////////////////////////////////////////////////////////////////////////////// 44 | // default_ 45 | template 46 | struct action_impl 47 | : detail::_block 48 | {}; 49 | 50 | template 51 | struct action_impl 52 | : detail::as_action_ 53 | {}; 54 | } 55 | } 56 | } 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /boost/proto/v5/action/everything.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // everything.hpp 3 | // 4 | // Copyright 2013 Eric Niebler. 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_ACTION_EVERYTHING_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_ACTION_EVERYTHING_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace boost 20 | { 21 | namespace proto 22 | { 23 | inline namespace v5 24 | { 25 | namespace detail 26 | { 27 | //////////////////////////////////////////////////////////////////////////////////// 28 | // reduce_ 29 | // Evaluate BinFun with 2 arguments, or return the second argument if the first 30 | // argument is "nothing". 31 | template 32 | struct reduce_ 33 | { 34 | template 35 | constexpr auto operator()(nothing const &, Value && value) const 36 | BOOST_PROTO_AUTO_RETURN( 37 | Value(static_cast(value)) 38 | ) 39 | 40 | template 41 | constexpr auto operator()(Value0 && v0, Value1 && v1) const 42 | BOOST_PROTO_AUTO_RETURN( 43 | BinFun()( 44 | static_cast(v0) 45 | , static_cast(v1) 46 | ) 47 | ) 48 | }; 49 | 50 | //////////////////////////////////////////////////////////////////////////////////// 51 | // _reduce_if_ 52 | template 53 | struct _reduce_if_ 54 | : def< 55 | match( 56 | case_...( 57 | as_grammar_ 58 | , reduce_(_state, as_action_) 59 | ) 60 | , default_( 61 | return_(_state) // avoid returning an rvalue ref to a temporary 62 | ) 63 | ) 64 | > 65 | {}; 66 | 67 | //////////////////////////////////////////////////////////////////////////////////// 68 | // _everything_ 69 | template 70 | struct _everything_ 71 | : def< 72 | match( 73 | case_( 74 | terminal(_) 75 | , _reduce_if_ 76 | ) 77 | , default_( 78 | _reduce_if_( 79 | _ 80 | , _env 81 | , fold(_, _state, _everything_) 82 | ) 83 | ) 84 | ) 85 | > 86 | {}; 87 | } 88 | 89 | struct everything 90 | {}; 91 | 92 | struct nothing 93 | {}; 94 | 95 | namespace extension 96 | { 97 | //////////////////////////////////////////////////////////////////////////////////// 98 | // e.g. everything(plus, case_(X, Y), case_(A, B)) 99 | template 100 | struct action_impl 101 | : detail::as_action_(_, _env, nothing())> 102 | {}; 103 | } 104 | } 105 | } 106 | } 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /boost/proto/v5/action/everywhere.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // everywhere.hpp 3 | // 4 | // Copyright 2013 Eric Niebler. 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_ACTION_EVERYWHERE_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_ACTION_EVERYWHERE_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost 21 | { 22 | namespace proto 23 | { 24 | inline namespace v5 25 | { 26 | namespace detail 27 | { 28 | //////////////////////////////////////////////////////////////////////////////////// 29 | // _replace_if_ 30 | template 31 | struct _replace_if_ 32 | : def< 33 | match( 34 | case_...( 35 | as_grammar_ 36 | , as_action_ 37 | ) 38 | , default_( 39 | return_(_) // avoid returning an rvalue ref to a temporary 40 | ) 41 | ) 42 | > 43 | {}; 44 | 45 | //////////////////////////////////////////////////////////////////////////////////// 46 | // _everywhere_ 47 | template 48 | struct _everywhere_ 49 | : def< 50 | match( 51 | case_( 52 | terminal(_) 53 | , _replace_if_ 54 | ) 55 | , default_( 56 | _replace_if_( 57 | passthru(_everywhere_...) 58 | ) 59 | ) 60 | ) 61 | > 62 | {}; 63 | } 64 | 65 | struct everywhere 66 | {}; 67 | 68 | namespace extension 69 | { 70 | //////////////////////////////////////////////////////////////////////////////////// 71 | // e.g. everywhere(case_(plus(_,_), minus(_left,_right))) 72 | template 73 | struct action_impl 74 | : detail::_everywhere_ 75 | {}; 76 | } 77 | } 78 | } 79 | } 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /boost/proto/v5/action/external.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // external.hpp 3 | // Contains definition of external actions. 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_ACTION_EXTERNAL_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_ACTION_EXTERNAL_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost 18 | { 19 | namespace proto 20 | { 21 | inline namespace v5 22 | { 23 | namespace detail 24 | { 25 | template 26 | struct _external_ 27 | : basic_action<_external_> 28 | { 29 | template 30 | constexpr utility::any operator()(Expr &&) const 31 | { 32 | static_assert( 33 | utility::never::value 34 | , "The proto::external action requires you to pass in an " 35 | "environment with mappings from rule names to actions." 36 | ); 37 | return utility::any(); 38 | } 39 | 40 | template 41 | constexpr auto operator()(Expr &&e, Env &&env, Rest &&...rest) const 42 | BOOST_PROTO_AUTO_RETURN( 43 | BOOST_PROTO_TRY_CALL(static_cast(env)(Rule()))( 44 | static_cast(e) 45 | , static_cast(env) 46 | , static_cast(rest)... 47 | ) 48 | ) 49 | }; 50 | } 51 | 52 | struct external 53 | {}; 54 | 55 | namespace extension 56 | { 57 | template 58 | struct action_impl 59 | : detail::_external_ 60 | {}; 61 | } 62 | } 63 | } 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /boost/proto/v5/action/if.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // if.hpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_PROTO_V5_ACTION_IF_HPP_INCLUDED 9 | #define BOOST_PROTO_V5_ACTION_IF_HPP_INCLUDED 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | namespace boost 19 | { 20 | namespace proto 21 | { 22 | inline namespace v5 23 | { 24 | /// \brief Used to select one grammar or another based on the result 25 | /// of a compile-time Boolean. When used as a basic_action, \c if_\<\> 26 | /// selects between two actions based on a compile-time Boolean. 27 | /// 28 | /// When if_\ is used as a grammar, \c If 29 | /// must be a Proto basic_action and \c Then and \c Else must be grammars. 30 | /// An expression type \c E matches if_\ if 31 | /// std::result_of\(E)\>::type::value 32 | /// is \c true and \c E matches \c U; or, if 33 | /// std::result_of\(E)\>::type::value 34 | /// is \c false and \c E matches \c V. 35 | /// 36 | /// The template parameter \c Then defaults to \c _ 37 | /// and \c Else defaults to \c not\<_\>, so an expression type \c E 38 | /// will match if_\ if and only if 39 | /// std::result_of\(E)\>::type::value 40 | /// is \c true. 41 | /// 42 | /// \code 43 | /// // A grammar that only matches integral terminals, 44 | /// // using is_integral<> from Boost.Type_traits. 45 | /// struct IsIntegral 46 | /// : and_< 47 | /// literal<_> 48 | /// , if_< is_integral<_value>() > 49 | /// > 50 | /// {}; 51 | /// \endcode 52 | /// 53 | /// When if_\ is used as a basic_action, \c If, 54 | /// \c Then and \c Else must be Proto actions. When applying 55 | /// the basic_action to an expression \c E, state \c S and data \c V, 56 | /// if boost::result_of\(E,S,V)\>::type::value 57 | /// is \c true then the \c Then basic_action is applied; otherwise 58 | /// the \c Else basic_action is applied. 59 | /// 60 | /// \code 61 | /// // Match a terminal. If the terminal is integral, return 62 | /// // mpl::true_; otherwise, return mpl::false_. 63 | /// struct IsIntegral2 64 | /// : when< 65 | /// literal<_> 66 | /// , if_< 67 | /// proto::make(is_integral<_value>()) 68 | /// , proto::make(std::true_type()) 69 | /// , proto::make(std::false_type()) 70 | /// > 71 | /// > 72 | /// {}; 73 | /// \endcode 74 | namespace detail 75 | { 76 | 77 | template 78 | struct _if_ 79 | : basic_action<_if_> 80 | { 81 | template 82 | auto operator()(Args &&... args) const 83 | BOOST_PROTO_AUTO_RETURN( 84 | call_action_< 85 | typename std::conditional< 86 | eval_bool_action_::value 87 | , Then 88 | , Else 89 | >::type 90 | >()(static_cast(args)...) 91 | ) 92 | }; 93 | } 94 | 95 | namespace extension 96 | { 97 | template 98 | struct action_impl 99 | : detail::_if_ 100 | {}; 101 | 102 | template 103 | struct action_impl 104 | : detail::_if_ 105 | {}; 106 | } 107 | } 108 | } 109 | } 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /boost/proto/v5/action/integral_constant.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // integral_constant.hpp 3 | // A simple basic_action that returns a constant 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_ACTION_INTEGRAL_CONSTANT_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_ACTION_INTEGRAL_CONSTANT_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace boost 17 | { 18 | namespace proto 19 | { 20 | inline namespace v5 21 | { 22 | template 23 | struct _integral_constant 24 | : basic_action<_integral_constant> 25 | { 26 | template 27 | constexpr T operator()(Args &&...) const noexcept(noexcept(T(std::declval()))) 28 | { 29 | return Value; 30 | } 31 | }; 32 | 33 | using _true = _integral_constant; 34 | using _false = _integral_constant; 35 | } 36 | } 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /boost/proto/v5/action/let.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // let.hpp 3 | // A BasicAction that creates local variables in a lexical scope 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_ACTION_LET_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_ACTION_LET_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace boost 17 | { 18 | namespace proto 19 | { 20 | inline namespace v5 21 | { 22 | namespace detail 23 | { 24 | template 25 | struct _eval_local_; 26 | 27 | template 28 | struct _eval_local_ 29 | : basic_action<_eval_local_> 30 | { 31 | template 32 | constexpr auto operator()(Args &&...args) const 33 | BOOST_PROTO_AUTO_RETURN( 34 | env_tag() = call_action_()(static_cast(args)...) 35 | ) 36 | }; 37 | 38 | template 39 | struct _let; 40 | 41 | template 42 | struct _let 43 | : basic_action<_let> 44 | { 45 | template 46 | constexpr auto operator()(Expr &&expr) const 47 | BOOST_PROTO_AUTO_RETURN( 48 | call_action_()( 49 | static_cast(expr) 50 | , proto::v5::make_env( 51 | _eval_local_()(static_cast(expr))... 52 | ) 53 | ) 54 | ) 55 | 56 | template 57 | constexpr auto operator()(Expr &&expr, Env &&env, Rest &&... rest) const 58 | BOOST_PROTO_AUTO_RETURN( 59 | call_action_()( 60 | static_cast(expr) 61 | , proto::v5::make_env( 62 | static_cast(env) 63 | , _eval_local_()( 64 | static_cast(expr) 65 | , static_cast(env) 66 | , static_cast(rest)... 67 | )... 68 | ) 69 | , static_cast(rest)... 70 | ) 71 | ) 72 | }; 73 | } 74 | 75 | template 76 | struct _local 77 | : basic_action<_local> 78 | { 79 | template 80 | constexpr auto operator()(Expr &&, Env &&env, Rest &&...) const 81 | BOOST_PROTO_AUTO_RETURN( 82 | static_cast(env)(static_cast(*this)) 83 | ) 84 | }; 85 | 86 | struct _a 87 | : _local<_a> 88 | {}; 89 | 90 | struct _b 91 | : _local<_b> 92 | {}; 93 | 94 | struct let 95 | {}; 96 | 97 | namespace extension 98 | { 99 | template 100 | struct action_impl 101 | : detail::_let< 102 | typename utility::result_of::back::type 103 | , typename utility::pop_back::type 104 | > 105 | {}; 106 | } 107 | } 108 | } 109 | } 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /boost/proto/v5/action/match.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // match.hpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_PROTO_V5_ACTION_MATCH_HPP_INCLUDED 9 | #define BOOST_PROTO_V5_ACTION_MATCH_HPP_INCLUDED 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | namespace boost 17 | { 18 | namespace proto 19 | { 20 | inline namespace v5 21 | { 22 | namespace detail 23 | { 24 | template 25 | struct is_case_stmt_ 26 | : std::false_type 27 | {}; 28 | 29 | template 30 | struct is_case_stmt_ 31 | : std::true_type 32 | {}; 33 | 34 | template 35 | struct is_case_stmt_ 36 | : std::true_type 37 | {}; 38 | 39 | template 40 | struct _match 41 | : basic_action<_match> 42 | { 43 | template 44 | constexpr auto operator()(Expr && e, Rest &&... rest) const 45 | BOOST_PROTO_AUTO_RETURN( 46 | call_action_< 47 | // This relies on details of how proto::match's grammar behavior is implemented. 48 | typename result_of::matches< 49 | Expr 50 | , proto::v5::match(ActiveGrammars...) 51 | >::which::proto_grammar_type 52 | >()( 53 | static_cast(e) 54 | , static_cast(rest)... 55 | ) 56 | ) 57 | }; 58 | } 59 | 60 | namespace extension 61 | { 62 | //////////////////////////////////////////////////////////////////////////////////////// 63 | // action_impl 64 | template 65 | struct action_impl 66 | : std::conditional< 67 | utility::logical_ops::and_(detail::is_case_stmt_::value...) 68 | , detail::_match 69 | , not_an_action 70 | >::type 71 | {}; 72 | } 73 | } 74 | } 75 | } 76 | 77 | #endif // BOOST_PROTO_V5_ACTION_MATCH_HPP_INCLUDED 78 | -------------------------------------------------------------------------------- /boost/proto/v5/action/matches.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // matches.hpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_PROTO_V5_ACTION_MATCHES_HPP_INCLUDED 9 | #define BOOST_PROTO_V5_ACTION_MATCHES_HPP_INCLUDED 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace boost 16 | { 17 | namespace proto 18 | { 19 | inline namespace v5 20 | { 21 | namespace detail 22 | { 23 | //////////////////////////////////////////////////////////////////////////////////// 24 | // _matches_ basic_action 25 | template 26 | struct _matches_ 27 | : proto::v5::basic_action<_matches_> 28 | { 29 | template 30 | constexpr auto operator()(Expr &&, Rest &&...) const 31 | BOOST_PROTO_AUTO_RETURN( 32 | proto::v5::result_of::matches() 33 | ) 34 | }; 35 | } 36 | 37 | //////////////////////////////////////////////////////////////////////////////////////// 38 | // matches_ 39 | struct matches_ 40 | {}; 41 | 42 | namespace extension 43 | { 44 | //////////////////////////////////////////////////////////////////////////////////// 45 | // action_impl 46 | template 47 | struct action_impl 48 | : detail::_matches_ 49 | {}; 50 | } 51 | } 52 | } 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /boost/proto/v5/action/not.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // not.hpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_PROTO_V5_ACTION_NOT_HPP_INCLUDED 9 | #define BOOST_PROTO_V5_ACTION_NOT_HPP_INCLUDED 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace boost 16 | { 17 | namespace proto 18 | { 19 | inline namespace v5 20 | { 21 | namespace detail 22 | { 23 | struct logical_not_ 24 | { 25 | template 26 | constexpr std::integral_constant(A::value)> 27 | operator()(A const &) const noexcept 28 | { 29 | return std::integral_constant(A::value)>(); 30 | } 31 | 32 | inline constexpr bool operator()(bool a) const noexcept 33 | { 34 | return !a; 35 | } 36 | }; 37 | 38 | template 39 | struct _not_ 40 | : basic_action<_not_> 41 | { 42 | template 43 | constexpr auto operator()(Args &&...args) const 44 | BOOST_PROTO_AUTO_RETURN( 45 | logical_not_()(call_action_()(static_cast(args)...)) 46 | ) 47 | }; 48 | } 49 | 50 | namespace extension 51 | { 52 | template 53 | struct action_impl 54 | : detail::_not_ 55 | {}; 56 | } 57 | } 58 | } 59 | } 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /boost/proto/v5/action/or.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // or.hpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_PROTO_V5_ACTION_OR_HPP_INCLUDED 9 | #define BOOST_PROTO_V5_ACTION_OR_HPP_INCLUDED 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace boost 16 | { 17 | namespace proto 18 | { 19 | inline namespace v5 20 | { 21 | namespace detail 22 | { 23 | struct logical_or_ 24 | { 25 | template 26 | constexpr std::integral_constant(A::value) || static_cast(B::value)> 27 | operator()(A const &, B const &) const noexcept 28 | { 29 | return std::integral_constant(A::value) || static_cast(B::value)>(); 30 | } 31 | 32 | template(B::value)> 33 | inline constexpr bool operator()(bool a, B const &) const noexcept 34 | { 35 | return a || BV; 36 | } 37 | 38 | template(A::value)> 39 | inline constexpr bool operator()(A const &, bool b) const noexcept 40 | { 41 | return AV || b; 42 | } 43 | 44 | inline constexpr bool operator()(bool a, bool b) const noexcept 45 | { 46 | return a || b; 47 | } 48 | }; 49 | 50 | struct fold_or_ 51 | { 52 | static constexpr std::false_type call() noexcept 53 | { 54 | return std::false_type(); 55 | } 56 | 57 | template 58 | static constexpr auto call(BoolHead const &bh, BoolTail const &...bt) 59 | BOOST_PROTO_AUTO_RETURN( 60 | BOOST_PROTO_TRY_CALL(logical_or_())(bh, Impl::call(bt...)) 61 | ) 62 | }; 63 | 64 | template 65 | struct _or_ 66 | : basic_action<_or_> 67 | { 68 | template 69 | constexpr auto operator()(Args &&...args) const 70 | BOOST_PROTO_AUTO_RETURN( 71 | fold_or_::call(call_action_()(static_cast(args)...)...) 72 | ) 73 | }; 74 | } 75 | 76 | namespace extension 77 | { 78 | template 79 | struct action_impl 80 | : detail::_or_ 81 | {}; 82 | } 83 | } 84 | } 85 | } 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /boost/proto/v5/action/placeholders.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // placeholders.hpp 3 | // Basic actions for accessing the arguments to the action. 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_ACTION_PLACEHOLDERS_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_ACTION_PLACEHOLDERS_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost 18 | { 19 | namespace proto 20 | { 21 | inline namespace v5 22 | { 23 | //////////////////////////////////////////////////////////////////////////////////////// 24 | // _expr 25 | struct _expr 26 | : basic_action<_expr> 27 | { 28 | template 29 | constexpr auto operator()(E && e, Rest &&...) const 30 | BOOST_PROTO_AUTO_RETURN( 31 | static_cast(e) 32 | ) 33 | }; 34 | 35 | //////////////////////////////////////////////////////////////////////////////////////// 36 | // _state 37 | struct _state 38 | : basic_action<_state> 39 | { 40 | template 41 | constexpr auto operator()(E &&, Env &&, S && s, Rest &&...) const 42 | BOOST_PROTO_AUTO_RETURN( 43 | static_cast(s) 44 | ) 45 | }; 46 | 47 | //////////////////////////////////////////////////////////////////////////////////////// 48 | // _data 49 | struct _data 50 | : detail::as_action_ 51 | {}; 52 | } 53 | } 54 | } 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /boost/proto/v5/action/protect.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // protect.hpp 3 | // Keep a basic_action from being applied when building the return type of 4 | // proto::make. 5 | // 6 | // Copyright 2012 Eric Niebler. Distributed under the Boost 7 | // Software License, Version 1.0. (See accompanying file 8 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | #ifndef BOOST_PROTO_V5_ACTION_PROTECT_HPP_INCLUDED 11 | #define BOOST_PROTO_V5_ACTION_PROTECT_HPP_INCLUDED 12 | 13 | #include 14 | #include 15 | 16 | namespace boost 17 | { 18 | namespace proto 19 | { 20 | inline namespace v5 21 | { 22 | /// \brief A BasicAction which prevents another BasicAction 23 | /// from being applied in an \c ObjectAction. 24 | /// 25 | /// When building higher order actions with make\<\> or 26 | /// lazy\<\>, you sometimes would like to build types that 27 | /// are parameterized with Proto actions. In such lambda-style 28 | /// actions, Proto will unhelpfully find all nested actions 29 | /// and apply them, even if you don't want them to be applied. Consider 30 | /// the following basic_action, which will replace the \c _ in 31 | /// Bar<_>() with proto::terminal\: 32 | /// 33 | /// \code 34 | /// template 35 | /// struct Bar 36 | /// {}; 37 | /// 38 | /// struct Foo 39 | /// : proto::when<_, Bar<_>() > 40 | /// {}; 41 | /// 42 | /// proto::literal i {0}; 43 | /// 44 | /// int main() 45 | /// { 46 | /// Foo()(i); 47 | /// std::cout << typeid(Foo()(i)).name() << std::endl; 48 | /// } 49 | /// \endcode 50 | /// 51 | /// If you were actually trying to pass the \c _ basic_action to \c Bar 52 | /// you can use \c proto::_protect: 53 | /// 54 | /// \code 55 | /// // OK: replace anything with Bar<_protect<_> >() 56 | /// struct Foo 57 | /// : proto::when<_, proto::make( Bar<_protect<_> >() ) > 58 | /// {}; 59 | /// \endcode 60 | /// 61 | /// _protect\ behaves just like action\ 62 | /// when used as a basic_action. 63 | template 64 | struct _protect 65 | : detail::as_action_ 66 | {}; 67 | } 68 | } 69 | } 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /boost/proto/v5/action/string.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // integral_constant.hpp 3 | // A simple basic_action that returns a constant 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_ACTION_STRING_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_ACTION_STRING_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace boost 17 | { 18 | namespace proto 19 | { 20 | inline namespace v5 21 | { 22 | template 23 | struct _string 24 | : basic_action<_string> 25 | { 26 | template 27 | constexpr char const *operator()(Args &&...) const noexcept 28 | { 29 | return mpl::c_str>::value; 30 | } 31 | }; 32 | } 33 | } 34 | } 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /boost/proto/v5/action/switch.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // switch.hpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_PROTO_V5_ACTION_SWITCH_HPP_INCLUDED 9 | #define BOOST_PROTO_V5_ACTION_SWITCH_HPP_INCLUDED 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace boost 16 | { 17 | namespace proto 18 | { 19 | inline namespace v5 20 | { 21 | /// \brief For matching one of a set of alternate grammars, which 22 | /// are looked up based on some property of an expression. The 23 | /// property on which to dispatch is specified by the \c Action 24 | /// template parameter, which defaults to tag_of\<_\>(). 25 | /// That is, when the \c Trannsform is not specified, the alternate 26 | /// grammar is looked up using the tag type of the current expression. 27 | /// 28 | /// When used as a basic_action, \c switch_\<\> applies the basic_action 29 | /// associated with the grammar that matches the expression. 30 | /// 31 | /// \note \c switch_\<\> is functionally identical to \c or_\<\> but 32 | /// is often more efficient. It does a fast, O(1) lookup using the 33 | /// result of the specified basic_action to find a sub-grammar that may 34 | /// potentially match the expression. 35 | /// 36 | /// An expression type \c E matches switch_\ if \c E 37 | /// matches C::case_\::type\>. 38 | /// 39 | /// When applying switch_\ as a basic_action with an 40 | /// expression \c e of type \c E, state \c s of type \S and data 41 | /// \c d of type \c D, it is equivalent to 42 | /// C::case_\::type\>()(e, s, d). 43 | namespace detail 44 | { 45 | template 46 | struct _switch_ 47 | : basic_action<_switch_> 48 | { 49 | template 50 | constexpr auto operator()(Args &&... args) const 51 | BOOST_PROTO_AUTO_RETURN( 52 | call_action_< 53 | typename Cases::template case_< 54 | decltype(call_action_()(static_cast(args)...)) 55 | > 56 | >()(static_cast(args)...) 57 | ) 58 | }; 59 | 60 | /// INTERNAL ONLY 61 | // pure compile-time optimization 62 | template 63 | struct _switch_ 64 | : basic_action<_switch_> 65 | { 66 | template 67 | constexpr auto operator()(Expr && e, Rest &&... rest) const 68 | BOOST_PROTO_AUTO_RETURN( 69 | call_action_< 70 | typename Cases::template case_< 71 | typename proto::v5::result_of::tag_of::type 72 | > 73 | >()(static_cast(e), static_cast(rest)...) 74 | ) 75 | }; 76 | } 77 | 78 | namespace extension 79 | { 80 | template 81 | struct action_impl 82 | : detail::_switch_ 83 | {}; 84 | 85 | template 86 | struct action_impl 87 | : detail::_switch_ 88 | {}; 89 | } 90 | } 91 | } 92 | } 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /boost/proto/v5/action/void.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // void.hpp 3 | // A no-op basic action that returns void. 4 | // 5 | // Copyright 2013 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_ACTION_VOID_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_ACTION_VOID_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | 15 | namespace boost 16 | { 17 | namespace proto 18 | { 19 | inline namespace v5 20 | { 21 | namespace detail 22 | { 23 | //////////////////////////////////////////////////////////////////////////////////// 24 | // _void_ 25 | struct _void_ 26 | : basic_action<_void_> 27 | { 28 | template 29 | void operator()(As &&...) const noexcept 30 | {} 31 | }; 32 | } 33 | 34 | namespace extension 35 | { 36 | //////////////////////////////////////////////////////////////////////////////////// 37 | // action_impl 38 | template<> 39 | struct action_impl 40 | : detail::_void_ 41 | {}; 42 | } 43 | } 44 | } 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /boost/proto/v5/core.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // core.hpp 3 | // Includes the core of Proto. Not included are the contexts, actions and 4 | // debugging utilities. 5 | // 6 | // Copyright 2008 Eric Niebler. Distributed under the Boost 7 | // Software License, Version 1.0. (See accompanying file 8 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | #ifndef BOOST_PROTO_V5_CORE_HPP_INCLUDED 11 | #define BOOST_PROTO_V5_CORE_HPP_INCLUDED 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /boost/proto/v5/deep_copy.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // deep_copy.hpp 3 | // Replace all nodes stored by reference with nodes stored by value. 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_DEEP_COPY_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_DEEP_COPY_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace boost 20 | { 21 | namespace proto 22 | { 23 | inline namespace v5 24 | { 25 | namespace detail 26 | { 27 | struct _deep_copy_cases 28 | { 29 | template 30 | struct case_ 31 | : as_action_ 32 | {}; 33 | 34 | template 35 | struct case_ 36 | : proto::v5::basic_action> 37 | { 38 | template 39 | constexpr auto operator()(E && e, Rest &&...) const 40 | BOOST_PROTO_AUTO_RETURN( 41 | typename result_of::domain_of::type::make_expr()( 42 | proto::v5::tag_of(static_cast(e)) 43 | , utility::by_val()(proto::v5::value(static_cast(e))) 44 | ) 45 | ) 46 | }; 47 | }; 48 | } 49 | 50 | //////////////////////////////////////////////////////////////////////////////////////// 51 | // _deep_copy 52 | // A BasicAction that replaces all nodes stored by reference with 53 | // nodes stored by value. 54 | struct _deep_copy 55 | : detail::as_action_ 56 | {}; 57 | 58 | //////////////////////////////////////////////////////////////////////////////////////// 59 | // deep_copy 60 | // Replaces all nodes stored by reference with nodes stored by value. 61 | template 62 | constexpr auto deep_copy(E && e) 63 | BOOST_PROTO_AUTO_RETURN( 64 | proto::v5::_deep_copy()(static_cast(e)) 65 | ) 66 | 67 | namespace functional 68 | { 69 | //////////////////////////////////////////////////////////////////////////////////// 70 | // deep_copy 71 | // A UnaryPolymorphicFunction that replaces all nodes stored by reference 72 | // with nodes stored by value. 73 | struct deep_copy 74 | { 75 | template 76 | constexpr auto operator()(E && e) const 77 | BOOST_PROTO_AUTO_RETURN( 78 | proto::v5::_deep_copy()(static_cast(e)) 79 | ) 80 | }; 81 | } 82 | } 83 | } 84 | } 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /boost/proto/v5/def.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // def.hpp 3 | // Helpers for building Proto grammars and actions. 4 | // 5 | // Copyright 2013 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_DEF_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_DEF_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost 18 | { 19 | namespace proto 20 | { 21 | inline namespace v5 22 | { 23 | namespace detail 24 | { 25 | //////////////////////////////////////////////////////////////////////////////////// 26 | struct def_base 27 | {}; 28 | } 29 | 30 | //////////////////////////////////////////////////////////////////////////////////////// 31 | template 32 | struct def 33 | : detail::def_base 34 | , detail::as_grammar_ 35 | , detail::as_action_ 36 | { 37 | static_assert( 38 | std::is_function::value 39 | , "Only use proto::def with function types." 40 | ); 41 | }; 42 | } 43 | } 44 | } 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /boost/proto/v5/detail/access.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // access.hpp 3 | // 4 | // Copyright 2013 Eric Niebler. 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_DETAIL_ACCESS_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_DETAIL_ACCESS_HPP_INCLUDED 11 | 12 | #include 13 | 14 | namespace boost 15 | { 16 | namespace proto 17 | { 18 | inline namespace v5 19 | { 20 | namespace exprs 21 | { 22 | struct access 23 | { 24 | //////////////////////////////////////////////////////////////////////////////// 25 | // basic_expr accessors 26 | template 27 | static Tag & proto_tag(basic_expr &e) noexcept 28 | { 29 | return e.tag_and_children_.first(); 30 | } 31 | 32 | template 33 | static constexpr Tag const & proto_tag(basic_expr const &e) noexcept 34 | { 35 | return e.tag_and_children_.first(); 36 | } 37 | 38 | template 39 | static constexpr Tag && proto_tag(basic_expr &&e) noexcept 40 | { 41 | return static_cast> &&>(e.tag_and_children_).first(); 42 | } 43 | 44 | template 45 | static children & proto_args(basic_expr &e) noexcept 46 | { 47 | return e.tag_and_children_.second(); 48 | } 49 | 50 | template 51 | static constexpr children const & proto_args(basic_expr const &e) noexcept 52 | { 53 | return e.tag_and_children_.second(); 54 | } 55 | 56 | template 57 | static constexpr children && proto_args(basic_expr &&e) noexcept 58 | { 59 | return static_cast> &&>(e.tag_and_children_).second(); 60 | } 61 | 62 | template 63 | static inline constexpr auto proto_equal_to( 64 | basic_expr const &lhs 65 | , basic_expr const &rhs) 66 | BOOST_PROTO_AUTO_RETURN( 67 | access::proto_args(lhs) == access::proto_args(rhs) 68 | ) 69 | }; 70 | } 71 | } 72 | } 73 | } 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /boost/proto/v5/detail/common_domain.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // common_domain.hpp 3 | // Contains definition of common_domain\<\> class template 4 | // for finding the domain that is common among the specified 5 | // domains 6 | // 7 | // Copyright 2012 Daniel Wallin, Eric Niebler. Distributed under the Boost 8 | // Software License, Version 1.0. (See accompanying file 9 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 10 | // 11 | // Many thanks to Daniel Wallin who first implemented this code. Thanks 12 | // also to Jeremiah Willcock, John Bytheway and Krishna Achuthan who 13 | // offered alternate solutions to this tricky programming problem. 14 | 15 | #ifndef BOOST_PROTO_V5_DETAIL_COMMON_DOMAIN_HPP_INCLUDED 16 | #define BOOST_PROTO_V5_DETAIL_COMMON_DOMAIN_HPP_INCLUDED 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #ifndef BOOST_PROTO_ASSERT_VALID_DOMAIN 24 | # define BOOST_PROTO_ASSERT_VALID_DOMAIN(DOM) \ 25 | static_assert(!std::is_same::value, "no common domain!") 26 | #endif 27 | 28 | namespace boost 29 | { 30 | namespace proto 31 | { 32 | inline namespace v5 33 | { 34 | namespace detail 35 | { 36 | template 37 | struct domain_ 38 | : domain_ 39 | { 40 | using type = Domain; 41 | using domain_::deduce; 42 | static Domain deduce(domain_*); 43 | }; 44 | 45 | template<> 46 | struct domain_ 47 | { 48 | using type = not_a_domain; 49 | static not_a_domain deduce(void*); 50 | }; 51 | 52 | template<> 53 | struct domain_ 54 | : domain_ 55 | {}; 56 | 57 | utility::sized_type<1> default_test(void*, void*); 58 | utility::sized_type<2> default_test(domain_*, void*); 59 | utility::sized_type<3> default_test(void*, domain_*); 60 | utility::sized_type<4> default_test(domain_*, domain_*); 61 | 62 | //////////////////////////////////////////////////////////////////////////////////// 63 | // common_domain2 64 | template< 65 | typename D0 66 | , typename D1 67 | , std::size_t DefaultCase = sizeof(proto::v5::detail::default_test((domain_*)0, (domain_*)0)) 68 | > 69 | struct common_domain2 70 | { 71 | using type = decltype(domain_::deduce((domain_*)0)); 72 | BOOST_PROTO_ASSERT_VALID_DOMAIN(type); 73 | }; 74 | 75 | template 76 | struct common_domain2 77 | { 78 | using type = D1; 79 | }; 80 | 81 | template 82 | struct common_domain2 83 | { 84 | using type = D0; 85 | }; 86 | 87 | template 88 | struct common_domain2 89 | { 90 | using type = D0; 91 | }; 92 | 93 | template 94 | struct common_domain2 95 | { 96 | using type = D1; 97 | }; 98 | 99 | template<> 100 | struct common_domain2 101 | { 102 | using type = default_domain; 103 | }; 104 | 105 | //////////////////////////////////////////////////////////////////////////////////// 106 | // common_domain 107 | template 108 | struct common_domain; 109 | 110 | template 111 | struct common_domain 112 | { 113 | using type = D0; 114 | }; 115 | 116 | template 117 | struct common_domain 118 | : common_domain2 119 | {}; 120 | 121 | template 122 | struct common_domain 123 | : common_domain::type, DS...> 124 | {}; 125 | } 126 | } 127 | } 128 | } 129 | 130 | #endif // BOOST_PROTO_V5_DETAIL_COMMON_DOMAIN_HPP_INCLUDED 131 | -------------------------------------------------------------------------------- /boost/proto/v5/detail/compressed_pair.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // compressed_pair.hpp 3 | // A subset of the functionality provided by boost::compressed_pair, but C++11-aware 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_DETAIL_COMPRESSED_PAIR_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_DETAIL_COMPRESSED_PAIR_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | 15 | namespace boost 16 | { 17 | namespace proto 18 | { 19 | inline namespace v5 20 | { 21 | namespace detail 22 | { 23 | template 24 | struct compressed_pair 25 | : private First 26 | , private Second 27 | { 28 | BOOST_PROTO_REGULAR_TRIVIAL_CLASS(compressed_pair); 29 | 30 | template 31 | constexpr compressed_pair(F && f, S && s) 32 | noexcept( 33 | noexcept(First(static_cast(f))) && 34 | noexcept(Second(static_cast(s))) 35 | ) 36 | : First(static_cast(f)) 37 | , Second(static_cast(s)) 38 | {} 39 | 40 | First & first() & noexcept 41 | { 42 | return *this; 43 | } 44 | 45 | constexpr First const & first() const & noexcept 46 | { 47 | return *this; 48 | } 49 | 50 | constexpr First && first() const && noexcept 51 | { 52 | return const_cast(*this); 53 | } 54 | 55 | Second & second() & noexcept 56 | { 57 | return *this; 58 | } 59 | 60 | constexpr Second const & second() const & noexcept 61 | { 62 | return *this; 63 | } 64 | 65 | constexpr Second && second() const && noexcept 66 | { 67 | return const_cast(*this); 68 | } 69 | }; 70 | } 71 | } 72 | } 73 | } 74 | 75 | #endif // BOOST_PROTO_V5_DETAIL_COMPRESSED_PAIR_HPP_INCLUDED 76 | -------------------------------------------------------------------------------- /boost/proto/v5/functional.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // functional.hpp 3 | // Proto callables for various things 4 | // 5 | // Copyright 2010 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/cxx.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // cxx.hpp 3 | // Proto callables corresponding to core language facilities 4 | // 5 | // Copyright 2010 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_CXX_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_CXX_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/cxx/cast.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // cast.hpp 3 | // Function objects for performing the various C++-style casts 4 | // 5 | // Copyright 2013 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_CXX_CAST_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_CXX_CAST_HPP_INCLUDED 11 | 12 | #include 13 | 14 | namespace boost 15 | { 16 | namespace proto 17 | { 18 | inline namespace v5 19 | { 20 | namespace functional 21 | { 22 | namespace cxx 23 | { 24 | //////////////////////////////////////////////////////////////////////////////////// 25 | // static_cast_ 26 | template 27 | struct static_cast_ 28 | { 29 | template 30 | constexpr auto operator()(U && u) const 31 | BOOST_PROTO_AUTO_RETURN( 32 | static_cast(static_cast(u)) 33 | ) 34 | }; 35 | 36 | //////////////////////////////////////////////////////////////////////////////////// 37 | // const_cast_ 38 | template 39 | struct const_cast_ 40 | { 41 | template 42 | constexpr auto operator()(U && u) const 43 | BOOST_PROTO_AUTO_RETURN( 44 | const_cast(static_cast(u)) 45 | ) 46 | }; 47 | 48 | //////////////////////////////////////////////////////////////////////////////////// 49 | // dynamic_cast_ 50 | template 51 | struct dynamic_cast_ 52 | { 53 | template 54 | constexpr auto operator()(U && u) const 55 | BOOST_PROTO_AUTO_RETURN( 56 | dynamic_cast(static_cast(u)) 57 | ) 58 | }; 59 | 60 | //////////////////////////////////////////////////////////////////////////////////// 61 | // reinterpret_cast_ 62 | template 63 | struct reinterpret_cast_ 64 | { 65 | template 66 | constexpr auto operator()(U && u) const 67 | BOOST_PROTO_AUTO_RETURN( 68 | reinterpret_cast(static_cast(u)) 69 | ) 70 | }; 71 | } 72 | } 73 | } 74 | } 75 | } 76 | 77 | #endif 78 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/cxx/construct.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // construct.hpp 3 | // A function object for constructing objects of a specified type. 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_CXX_CONSTRUCT_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_CXX_CONSTRUCT_HPP_INCLUDED 11 | 12 | #include 13 | 14 | namespace boost 15 | { 16 | namespace proto 17 | { 18 | inline namespace v5 19 | { 20 | namespace functional 21 | { 22 | namespace cxx 23 | { 24 | //////////////////////////////////////////////////////////////////////////////////// 25 | // construct 26 | template 27 | struct construct 28 | { 29 | template 30 | constexpr auto operator()(Args &&... args) const 31 | BOOST_PROTO_AUTO_RETURN( 32 | Type{static_cast(args)...} 33 | ) 34 | }; 35 | } 36 | } 37 | } 38 | } 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/cxx/throw.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // throw.hpp 3 | // Function object for throwing objects 4 | // 5 | // Copyright 2013 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_CXX_THROW_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_CXX_THROW_HPP_INCLUDED 11 | 12 | #include 13 | 14 | namespace boost 15 | { 16 | namespace proto 17 | { 18 | inline namespace v5 19 | { 20 | namespace functional 21 | { 22 | namespace cxx 23 | { 24 | //////////////////////////////////////////////////////////////////////////////////// 25 | // throw_ 26 | struct throw_ 27 | { 28 | template 29 | [[noreturn]] void operator()(U && u) const 30 | { 31 | throw static_cast(u); 32 | } 33 | }; 34 | } 35 | } 36 | } 37 | } 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/fusion.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // fusion.hpp 3 | // Proto callables for things found in the Fusion library 4 | // 5 | // Copyright 2010 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_FUSION_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_FUSION_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/fusion/at.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // at.hpp 3 | // Proto callables Fusion at 4 | // 5 | // Copyright 2010 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_FUSION_AT_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_FUSION_AT_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | 15 | namespace boost 16 | { 17 | namespace proto 18 | { 19 | inline namespace v5 20 | { 21 | namespace functional 22 | { 23 | namespace fusion 24 | { 25 | /// \brief A PolymorphicFunctionObject type that invokes the 26 | /// \c fusion::at() accessor on its argument. 27 | /// 28 | /// A PolymorphicFunctionObject type that invokes the 29 | /// \c fusion::at() accessor on its argument. 30 | struct at 31 | { 32 | template 33 | auto operator ()(Seq &&seq, N const &) const 34 | BOOST_PROTO_AUTO_RETURN( 35 | boost::fusion::at(static_cast(seq)) 36 | ) 37 | }; 38 | } 39 | } 40 | } 41 | } 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/fusion/pop_back.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // pop_back.hpp 3 | // Proto callables Fusion pop_back 4 | // 5 | // Copyright 2010 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_FUSION_POP_BACK_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_FUSION_POP_BACK_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace boost 20 | { 21 | namespace proto 22 | { 23 | inline namespace v5 24 | { 25 | namespace functional 26 | { 27 | namespace fusion 28 | { 29 | /// \brief A PolymorphicFunctionObject type that invokes the 30 | /// \c fusion::pop_back() action on its argument. 31 | /// 32 | /// A PolymorphicFunctionObject type that invokes the 33 | /// \c fusion::pop_back() action on its argument. 34 | struct pop_back 35 | { 36 | template 37 | auto operator ()(Seq &&seq) const 38 | BOOST_PROTO_AUTO_RETURN( 39 | typename boost::fusion::result_of::pop_back< 40 | typename ::std::remove_reference::type 41 | >::type( 42 | boost::fusion::begin(static_cast(seq)) 43 | , boost::fusion::prior(boost::fusion::end(static_cast(seq))) 44 | ) 45 | ) 46 | }; 47 | } 48 | } 49 | } 50 | } 51 | } 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/fusion/pop_front.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // pop_front.hpp 3 | // Proto callables Fusion pop_front 4 | // 5 | // Copyright 2010 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_FUSION_POP_FRONT_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_FUSION_POP_FRONT_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace boost 20 | { 21 | namespace proto 22 | { 23 | inline namespace v5 24 | { 25 | namespace functional 26 | { 27 | namespace fusion 28 | { 29 | /// \brief A PolymorphicFunctionObject type that invokes the 30 | /// \c fusion::pop_front() action on its argument. 31 | /// 32 | /// A PolymorphicFunctionObject type that invokes the 33 | /// \c fusion::pop_front() action on its argument. This is 34 | /// useful for defining a CallableAction like \c pop_front(_) 35 | /// which removes the first child from a Proto expression node. 36 | /// Such a basic_action might be used as the first argument to the 37 | /// \c proto::fold\<\> basic_action; that is, fold all but 38 | /// the first child. 39 | struct pop_front 40 | { 41 | template 42 | auto operator ()(Seq &&seq) const 43 | BOOST_PROTO_AUTO_RETURN( 44 | typename boost::fusion::result_of::pop_front< 45 | typename ::std::remove_reference::type 46 | >::type( 47 | boost::fusion::next(boost::fusion::begin(static_cast(seq))) 48 | , boost::fusion::end(static_cast(seq)) 49 | ) 50 | ) 51 | }; 52 | } 53 | } 54 | } 55 | } 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/fusion/push_back.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // push_back.hpp 3 | // Proto callables Fusion push_back 4 | // 5 | // Copyright 2010 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_FUSION_PUSH_BACK_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_FUSION_PUSH_BACK_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | 15 | namespace boost 16 | { 17 | namespace proto 18 | { 19 | inline namespace v5 20 | { 21 | namespace functional 22 | { 23 | namespace fusion 24 | { 25 | /// \brief A PolymorphicFunctionObject type that invokes the 26 | /// \c fusion::push_back() action on its argument. 27 | /// 28 | /// A PolymorphicFunctionObject type that invokes the 29 | /// \c fusion::push_back() action on its argument. 30 | struct push_back 31 | { 32 | template 33 | auto operator ()(Seq &&seq, T &&t) const 34 | BOOST_PROTO_AUTO_RETURN( 35 | boost::fusion::push_back(static_cast(seq), static_cast(t)) 36 | ) 37 | }; 38 | } 39 | } 40 | } 41 | } 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/fusion/push_front.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // push_front.hpp 3 | // Proto callables Fusion push_front 4 | // 5 | // Copyright 2010 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_FUSION_PUSH_FRONT_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_FUSION_PUSH_FRONT_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | 15 | namespace boost 16 | { 17 | namespace proto 18 | { 19 | inline namespace v5 20 | { 21 | namespace functional 22 | { 23 | namespace fusion 24 | { 25 | /// \brief A PolymorphicFunctionObject type that invokes the 26 | /// \c fusion::push_front() action on its argument. 27 | /// 28 | /// A PolymorphicFunctionObject type that invokes the 29 | /// \c fusion::push_front() action on its argument. 30 | struct push_front 31 | { 32 | template 33 | auto operator ()(Seq &&seq, T &&t) const 34 | BOOST_PROTO_AUTO_RETURN( 35 | boost::fusion::push_front(static_cast(seq), static_cast(t)) 36 | ) 37 | }; 38 | } 39 | } 40 | } 41 | } 42 | } 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/fusion/reverse.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // reverse.hpp 3 | // Proto callables Fusion reverse 4 | // 5 | // Copyright 2010 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_FUSION_REVERSE_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_FUSION_REVERSE_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace boost 17 | { 18 | namespace proto 19 | { 20 | inline namespace v5 21 | { 22 | namespace functional 23 | { 24 | namespace fusion 25 | { 26 | /// \brief A PolymorphicFunctionObject type that invokes the 27 | /// \c fusion::reverse() action on its argument. 28 | /// 29 | /// A PolymorphicFunctionObject type that invokes the 30 | /// \c fusion::reverse() action on its argument. This is 31 | /// useful for defining a CallableAction like \c reverse(_) 32 | /// which reverses the order of the children of a Proto 33 | /// expression node. 34 | struct reverse 35 | { 36 | template 37 | auto operator ()(Seq &&seq) const 38 | BOOST_PROTO_AUTO_RETURN( 39 | typename boost::fusion::result_of::reverse< 40 | typename ::std::remove_reference::type 41 | >::type( 42 | static_cast(seq) 43 | ) 44 | ) 45 | }; 46 | } 47 | } 48 | } 49 | } 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/range.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // range.hpp 3 | // Proto callables for things found in the boost range library 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_RANGE_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_RANGE_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/range/begin.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // begin.hpp 3 | // Proto callables for boost::begin() 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_RANGE_BEGIN_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_RANGE_BEGIN_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | 15 | namespace boost 16 | { 17 | namespace proto 18 | { 19 | inline namespace v5 20 | { 21 | namespace functional 22 | { 23 | namespace range 24 | { 25 | // A PolymorphicFunctionObject that wraps boost::begin() 26 | struct begin 27 | { 28 | template 29 | auto operator()(Rng &&rng) const 30 | BOOST_PROTO_AUTO_RETURN( 31 | boost::begin(static_cast(rng)) 32 | ) 33 | }; 34 | } 35 | } 36 | } 37 | } 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/range/empty.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // empty.hpp 3 | // Proto callables for boost::empty() 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_RANGE_EMPTY_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_RANGE_EMPTY_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | 15 | namespace boost 16 | { 17 | namespace proto 18 | { 19 | inline namespace v5 20 | { 21 | namespace functional 22 | { 23 | namespace range 24 | { 25 | // A PolymorphicFunctionObject that wraps boost::empty() 26 | struct empty 27 | { 28 | template 29 | bool operator()(Rng const &rng) const noexcept(noexcept(boost::empty(rng))) 30 | { 31 | return boost::empty(rng); 32 | } 33 | }; 34 | } 35 | } 36 | } 37 | } 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/range/end.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // end.hpp 3 | // Proto callables for boost::end() 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_RANGE_END_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_RANGE_END_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | 15 | namespace boost 16 | { 17 | namespace proto 18 | { 19 | inline namespace v5 20 | { 21 | namespace functional 22 | { 23 | namespace range 24 | { 25 | // A PolymorphicFunctionObject that wraps boost::end() 26 | struct end 27 | { 28 | template 29 | auto operator()(Rng &&rng) const 30 | BOOST_PROTO_AUTO_RETURN( 31 | boost::end(static_cast(rng)) 32 | ) 33 | }; 34 | } 35 | } 36 | } 37 | } 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/range/rbegin.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // rbegin.hpp 3 | // Proto callables for boost::rbegin() 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_RANGE_RBEGIN_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_RANGE_RBEGIN_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | 15 | namespace boost 16 | { 17 | namespace proto 18 | { 19 | inline namespace v5 20 | { 21 | namespace functional 22 | { 23 | namespace range 24 | { 25 | // A PolymorphicFunctionObject that wraps boost::rbegin() 26 | struct rbegin 27 | { 28 | template 29 | auto operator()(Rng &&rng) const 30 | BOOST_PROTO_AUTO_RETURN( 31 | boost::rbegin(static_cast(rng)) 32 | ) 33 | }; 34 | } 35 | } 36 | } 37 | } 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/range/rend.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // rend.hpp 3 | // Proto callables for boost::rend() 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_RANGE_REND_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_RANGE_REND_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | 15 | namespace boost 16 | { 17 | namespace proto 18 | { 19 | inline namespace v5 20 | { 21 | namespace functional 22 | { 23 | namespace range 24 | { 25 | // A PolymorphicFunctionObject that wraps boost::rend() 26 | struct rend 27 | { 28 | template 29 | auto operator()(Rng &&rng) const 30 | BOOST_PROTO_AUTO_RETURN( 31 | boost::rend(static_cast(rng)) 32 | ) 33 | }; 34 | } 35 | } 36 | } 37 | } 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/range/size.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // size.hpp 3 | // Proto callables for boost::size() 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_RANGE_SIZE_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_RANGE_SIZE_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | 15 | namespace boost 16 | { 17 | namespace proto 18 | { 19 | inline namespace v5 20 | { 21 | namespace functional 22 | { 23 | namespace range 24 | { 25 | // A PolymorphicFunctionObject that wraps boost::size() 26 | struct size 27 | { 28 | template 29 | auto operator()(Rng const &rng) const 30 | BOOST_PROTO_AUTO_RETURN( 31 | boost::size(rng) 32 | ) 33 | }; 34 | 35 | }}}}} 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/std.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // std.hpp 3 | // Proto callables for things found in the std library 4 | // 5 | // Copyright 2010 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_STD_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_STD_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/std/iterator.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // iterator.hpp 3 | // Proto callables for std functions found in \ 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_STD_ITERATOR_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_STD_ITERATOR_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | 15 | namespace boost 16 | { 17 | namespace proto 18 | { 19 | inline namespace v5 20 | { 21 | namespace functional 22 | { 23 | namespace std 24 | { 25 | // A PolymorphicFunctionObject wrapping std::advance 26 | struct advance 27 | { 28 | template 29 | void operator()(InputIterator &x, Distance n) const noexcept(noexcept(std::advance(x, n))) 30 | { 31 | ::std::advance(x, n); 32 | } 33 | }; 34 | 35 | // A PolymorphicFunctionObject wrapping std::distance 36 | struct distance 37 | { 38 | template 39 | auto operator()(InputIterator first, InputIterator last) const 40 | BOOST_PROTO_AUTO_RETURN( 41 | ::std::distance(first, last) 42 | ) 43 | }; 44 | 45 | // A PolymorphicFunctionObject wrapping std::next 46 | struct next 47 | { 48 | template 49 | ForwardIterator operator()( 50 | ForwardIterator x 51 | , typename ::std::iterator_traits::difference_type n = 1 52 | ) const noexcept(noexcept(ForwardIterator(std::next(x, n)))) 53 | { 54 | return ::std::next(x, n); 55 | } 56 | }; 57 | 58 | // A PolymorphicFunctionObject wrapping std::prior 59 | struct prior 60 | { 61 | template 62 | BidirectionalIterator operator()( 63 | BidirectionalIterator x 64 | , typename ::std::iterator_traits::difference_type n = 1 65 | ) const noexcept(noexcept(BidirectionalIterator(std::advance(x, -n)))) 66 | { 67 | return ::std::advance(x, -n); 68 | } 69 | }; 70 | } 71 | } 72 | } 73 | } 74 | } 75 | 76 | #endif 77 | -------------------------------------------------------------------------------- /boost/proto/v5/functional/std/utility.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // utility.hpp 3 | // Proto callables for things found in the std \ header 4 | // 5 | // Copyright 2010 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_FUNCTIONAL_STD_UTILITY_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_FUNCTIONAL_STD_UTILITY_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | 15 | namespace boost 16 | { 17 | namespace proto 18 | { 19 | inline namespace v5 20 | { 21 | namespace functional 22 | { 23 | namespace std 24 | { 25 | /// \brief A PolymorphicFunctionObject type that invokes the 26 | /// \c std::make_pair() action on its arguments. 27 | /// 28 | /// A PolymorphicFunctionObject type that invokes the 29 | /// \c std::make_pair() action on its arguments. 30 | struct make_pair 31 | { 32 | template 33 | auto operator()(First &&first, Second &&second) const 34 | BOOST_PROTO_AUTO_RETURN( 35 | ::std::make_pair(::std::forward(first), ::std::forward(second)) 36 | ) 37 | }; 38 | 39 | /// \brief A PolymorphicFunctionObject type that returns 40 | /// the first element of a std::pair. 41 | /// 42 | /// A PolymorphicFunctionObject type that returns 43 | /// the first element of a std::pair.. 44 | struct first 45 | { 46 | template 47 | constexpr auto operator()(Pair &&pair) const 48 | BOOST_PROTO_AUTO_RETURN( 49 | (static_cast(pair).first) // extra parens are significant! 50 | ) 51 | }; 52 | 53 | /// \brief A PolymorphicFunctionObject type that returns 54 | /// the second element of a std::pair. 55 | /// 56 | /// A PolymorphicFunctionObject type that returns 57 | /// the second element of a std::pair.. 58 | struct second 59 | { 60 | template 61 | constexpr auto operator()(Pair &&pair) const 62 | BOOST_PROTO_AUTO_RETURN( 63 | (static_cast(pair).second) // extra parens are significant! 64 | ) 65 | }; 66 | } 67 | } 68 | } 69 | } 70 | } 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /boost/proto/v5/grammar.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // grammar.hpp 3 | // Contains all Proto's grammar-building facilities. 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_GRAMMAR_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_GRAMMAR_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /boost/proto/v5/grammar/and.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // and.hpp 3 | // Contains the behavior of proto::and_ when used as a grammar element. 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_GRAMMAR_AND_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_GRAMMAR_AND_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost 18 | { 19 | namespace proto 20 | { 21 | inline namespace v5 22 | { 23 | namespace extension 24 | { 25 | // Handle proto::and_ 26 | template 27 | struct grammar_impl 28 | { 29 | template 30 | struct apply 31 | : utility::and_...> 32 | {}; 33 | }; 34 | } 35 | } 36 | } 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /boost/proto/v5/grammar/case.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // case.hpp 3 | // Contains the behavior of proto::case when used as a grammar element. 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_GRAMMAR_CASE_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_GRAMMAR_CASE_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost 18 | { 19 | namespace proto 20 | { 21 | inline namespace v5 22 | { 23 | namespace extension 24 | { 25 | //////////////////////////////////////////////////////////////////////////////////// 26 | // case_ 27 | template 28 | struct grammar_impl 29 | { 30 | template 31 | struct apply 32 | : result_of::matches 33 | {}; 34 | }; 35 | 36 | //////////////////////////////////////////////////////////////////////////////////// 37 | // default_ 38 | template 39 | struct grammar_impl 40 | { 41 | template 42 | struct apply 43 | : std::true_type 44 | {}; 45 | }; 46 | } 47 | } 48 | } 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /boost/proto/v5/grammar/if.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // if.hpp 3 | // Contains the behavior of proto::if_ when used as a grammar element. 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_GRAMMAR_IF_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_GRAMMAR_IF_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace boost 17 | { 18 | namespace proto 19 | { 20 | inline namespace v5 21 | { 22 | namespace extension 23 | { 24 | // Handle proto::if_ in a matching context 25 | template 26 | struct grammar_impl 27 | { 28 | template 29 | struct apply 30 | : detail::eval_bool_action_ 31 | {}; 32 | }; 33 | } 34 | } 35 | } 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /boost/proto/v5/grammar/match.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // match.hpp 3 | // Contains the behavior of proto::match when used as a grammar element. 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_GRAMMAR_MATCH_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_GRAMMAR_MATCH_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost 18 | { 19 | namespace proto 20 | { 21 | inline namespace v5 22 | { 23 | namespace detail 24 | { 25 | //////////////////////////////////////////////////////////////////////////////////// 26 | // matches_wrap_ 27 | template 28 | struct matches_wrap_ 29 | : result_of::matches 30 | { 31 | using proto_grammar_type = Grammar; 32 | }; 33 | } 34 | 35 | namespace extension 36 | { 37 | // Handle proto::match 38 | template 39 | struct grammar_impl 40 | { 41 | template 42 | struct apply 43 | : utility::or_...> 44 | {}; 45 | }; 46 | } 47 | } 48 | } 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /boost/proto/v5/grammar/not.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // not.hpp 3 | // Contains the behavior of proto::not_ when used as a grammar element. 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_GRAMMAR_NOT_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_GRAMMAR_NOT_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | namespace boost 18 | { 19 | namespace proto 20 | { 21 | inline namespace v5 22 | { 23 | namespace extension 24 | { 25 | // Handle proto::not_ 26 | template 27 | struct grammar_impl 28 | { 29 | template 30 | struct apply 31 | : std::integral_constant< 32 | bool 33 | , !detail::eval_bool_action_::value 34 | > 35 | {}; 36 | }; 37 | } 38 | } 39 | } 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /boost/proto/v5/grammar/or.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // or.hpp 3 | // Contains the behavior of proto::or_ when used as a grammar element. 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_GRAMMAR_OR_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_GRAMMAR_OR_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace boost 17 | { 18 | namespace proto 19 | { 20 | inline namespace v5 21 | { 22 | namespace extension 23 | { 24 | // Handle proto::or_ 25 | template 26 | struct grammar_impl 27 | { 28 | template 29 | struct apply 30 | : utility::or_...> 31 | {}; 32 | }; 33 | } 34 | } 35 | } 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /boost/proto/v5/grammar/placeholders.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // placeholders.hpp 3 | // Basic placeholder grammars, including the proto::_ wildcard. 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_GRAMMAR_PLACEHOLDERS_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_GRAMMAR_PLACEHOLDERS_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /boost/proto/v5/grammar/switch.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // switch.hpp 3 | // Contains the behavior of proto::switch_ when used as a grammar element. 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_GRAMMAR_SWITCH_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_GRAMMAR_SWITCH_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace boost 21 | { 22 | namespace proto 23 | { 24 | inline namespace v5 25 | { 26 | namespace extension 27 | { 28 | // Handle proto::switch_ 29 | template 30 | struct grammar_impl 31 | { 32 | template 33 | struct apply 34 | : result_of::matches< 35 | Expr 36 | , typename Cases::template case_::type> 37 | > 38 | {}; 39 | }; 40 | 41 | template 42 | struct grammar_impl 43 | { 44 | template 45 | struct apply 46 | : result_of::matches< 47 | Expr 48 | , typename Cases::template case_()(std::declval()))> 49 | > 50 | {}; 51 | }; 52 | } 53 | } 54 | } 55 | } 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /boost/proto/v5/literals.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // literals.hpp 3 | // 4 | // Copyright 2012 Eric Niebler. 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_LITERALS_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_LITERALS_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | 15 | namespace boost 16 | { 17 | namespace proto 18 | { 19 | inline namespace v5 20 | { 21 | // handy user-defined literal operators for building expressions 22 | namespace literals 23 | { 24 | inline constexpr literal operator "" _et(char const *ntbs, std::size_t) noexcept 25 | { 26 | return literal(ntbs); 27 | } 28 | 29 | inline constexpr literal operator "" _et(wchar_t const *ntws, std::size_t) noexcept 30 | { 31 | return literal(ntws); 32 | } 33 | 34 | inline constexpr literal operator "" _et(char16_t const *ntws, std::size_t) noexcept 35 | { 36 | return literal(ntws); 37 | } 38 | 39 | inline constexpr literal operator "" _et(char32_t const *ntws, std::size_t) noexcept 40 | { 41 | return literal(ntws); 42 | } 43 | 44 | inline constexpr literal operator "" _et(char ch) noexcept 45 | { 46 | return literal(ch); 47 | } 48 | 49 | inline constexpr literal operator "" _et(wchar_t ch) noexcept 50 | { 51 | return literal(ch); 52 | } 53 | 54 | inline constexpr literal operator "" _et(char16_t ch) noexcept 55 | { 56 | return literal(ch); 57 | } 58 | 59 | inline constexpr literal operator "" _et(char32_t ch) noexcept 60 | { 61 | return literal(ch); 62 | } 63 | 64 | inline constexpr literal operator "" _et(unsigned long long l) noexcept 65 | { 66 | return literal(l); 67 | } 68 | 69 | inline constexpr literal operator "" _et(long double d) noexcept 70 | { 71 | return literal(d); 72 | } 73 | } 74 | } 75 | } 76 | } 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /boost/proto/v5/placeholders.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // placeholders.hpp 3 | // The proto::_ wildcard for use as a grammar element and also as a trivial action. 4 | // 5 | // Copyright 2012 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_PLACEHOLDERS_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_PLACEHOLDERS_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | namespace boost 17 | { 18 | namespace proto 19 | { 20 | inline namespace v5 21 | { 22 | /// \brief A wildcard grammar element that matches any expression, 23 | /// and a basic_action that returns the current expression unchanged. 24 | /// 25 | /// The wildcard type, \c _, is a grammar element such that 26 | /// matches\::value is \c true for any expression 27 | /// type \c E. 28 | /// 29 | /// The wildcard can also be used as a stand-in for a template 30 | /// argument when matching terminals. For instance, the following 31 | /// is a grammar that will match any std::complex\<\> 32 | /// terminal: 33 | /// 34 | /// \code 35 | /// BOOST_MPL_ASSERT(( 36 | /// matches< 37 | /// expr)> 38 | /// , terminal(std::complex< _ >) 39 | /// > 40 | /// )); 41 | /// \endcode 42 | /// 43 | /// When used as a basic_action, \c _ returns the current expression 44 | /// unchanged. For instance, in the following, \c _ is used with 45 | /// the \c _fold\<\> basic_action to _fold the children of a node: 46 | /// 47 | /// \code 48 | /// struct CountChildren 49 | /// : or_< 50 | /// // Terminals have no children 51 | /// when, mpl::int_<0>()> 52 | /// // Use _fold<> to count the children of non-terminals 53 | /// , otherwise< 54 | /// _fold< 55 | /// _ // <-- _fold the current expression 56 | /// , mpl::int_<0>() 57 | /// , mpl::plus<_state, mpl::int_<1>>() 58 | /// > 59 | /// > 60 | /// > 61 | /// {}; 62 | /// \endcode 63 | struct _ 64 | : basic_action<_> 65 | , basic_grammar<_> 66 | { 67 | template 68 | constexpr auto operator()(Expr && e, Rest &&...) const 69 | BOOST_PROTO_AUTO_RETURN( 70 | static_cast(e) 71 | ) 72 | 73 | // Makes _ a basic grammar element: 74 | template 75 | struct apply 76 | : std::true_type 77 | {}; 78 | }; 79 | } 80 | } 81 | } 82 | 83 | #endif 84 | -------------------------------------------------------------------------------- /boost/proto/v5/proto.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // proto.hpp 3 | // 4 | // Copyright 2012 Eric Niebler. 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_PROTO_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_PROTO_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /boost/proto/v5/virtual_member.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // virtual_member.hpp 3 | // 4 | // Copyright 2012 Eric Niebler. 5 | // Distributed under the Boost Software License, Version 1.0. (See 6 | // accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef BOOST_PROTO_V5_VIRTUAL_MEMBER_HPP_INCLUDED 10 | #define BOOST_PROTO_V5_VIRTUAL_MEMBER_HPP_INCLUDED 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | // INTERNAL ONLY 22 | // 23 | #define BOOST_PROTO_EXTENDS_MEMBER_DETAIL(R, THIS, ELEM) \ 24 | boost::proto::v5::virtual_member< \ 25 | THIS \ 26 | , BOOST_PP_TUPLE_ELEM(2, 0, ELEM) \ 27 | > BOOST_PP_TUPLE_ELEM(2, 1, ELEM); \ 28 | /**/ 29 | 30 | // \brief For declaring virtual data members in an extension class. 31 | // 32 | #define BOOST_PROTO_EXTENDS_MEMBERS(THIS, SEQ) \ 33 | union \ 34 | { \ 35 | char proto_member_union_start_; \ 36 | BOOST_PP_SEQ_FOR_EACH(BOOST_PROTO_EXTENDS_MEMBER_DETAIL, THIS, SEQ) \ 37 | } \ 38 | /**/ 39 | 40 | namespace boost 41 | { 42 | namespace proto 43 | { 44 | inline namespace v5 45 | { 46 | namespace exprs 47 | { 48 | //////////////////////////////////////////////////////////////////////////////////// 49 | // virtual_ 50 | template 51 | struct virtual_ 52 | : Expr 53 | {}; 54 | 55 | //////////////////////////////////////////////////////////////////////////////////// 56 | // virtual_member_ 57 | template 58 | struct virtual_member_, B)> 59 | : basic_expr, B)> 60 | , expr_assign, B)>> 61 | , expr_subscript, B)>> 62 | , expr_function, B)>> 63 | { 64 | BOOST_PROTO_REGULAR_TRIVIAL_CLASS(virtual_member_); 65 | using expr_assign::operator=; 66 | }; 67 | } 68 | } 69 | } 70 | } 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /libs/proto/v5/example/Jamfile: -------------------------------------------------------------------------------- 1 | # (C) Copyright 2012: Eric Niebler 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | 5 | project 6 | : requirements 7 | -Wno-multichar 8 | ; 9 | 10 | exe lambda 11 | : 12 | lambda.cpp 13 | ; 14 | 15 | exe map_list_of 16 | : 17 | map_list_of.cpp 18 | ; 19 | 20 | exe virtual_member 21 | : 22 | virtual_member.cpp 23 | ; 24 | -------------------------------------------------------------------------------- /libs/proto/v5/example/lambda.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // lambda.cpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace proto = boost::proto; 15 | using proto::_; 16 | 17 | template 18 | struct placeholder 19 | : proto::env_tag> 20 | { 21 | BOOST_PROTO_REGULAR_TRIVIAL_CLASS(placeholder); 22 | using proto::env_tag>::operator=; 23 | 24 | // So placeholder terminals can be pretty-printed with display_expr 25 | friend std::ostream & operator << (std::ostream & s, placeholder) 26 | { 27 | return s << "_" << T::value + 1; 28 | } 29 | }; 30 | 31 | template 32 | using placeholder_c = placeholder>; 33 | 34 | struct lambda_eval 35 | : proto::def< 36 | proto::match( 37 | proto::case_( proto::terminal(placeholder<_>), 38 | proto::get_env(proto::_value) 39 | ) 40 | , proto::case_( proto::terminal(_), 41 | proto::_value 42 | ) 43 | , proto::default_( 44 | proto::eval_with(lambda_eval) 45 | ) 46 | ) 47 | > 48 | {}; 49 | 50 | template 51 | inline auto lambda_eval_(proto::utility::indices, E && e, T &&... t) 52 | BOOST_PROTO_AUTO_RETURN( 53 | lambda_eval()( 54 | std::forward(e) 55 | , proto::make_env(placeholder_c() = std::forward(t)...) 56 | ) 57 | ) 58 | 59 | template 60 | struct lambda_expr 61 | : proto::basic_expr> 62 | , proto::expr_assign> 63 | , proto::expr_subscript> 64 | { 65 | using proto::basic_expr::basic_expr; 66 | using proto::expr_assign::operator=; 67 | 68 | template 69 | auto operator()(T &&... t) const 70 | BOOST_PROTO_AUTO_RETURN( 71 | lambda_eval_( 72 | proto::utility::make_indices() 73 | , *this, std::forward(t)... 74 | ) 75 | ) 76 | }; 77 | 78 | template 79 | using lambda_var = proto::custom>::terminal; 80 | 81 | namespace 82 | { 83 | constexpr auto const & _1 = proto::utility::static_const>>::value; 84 | constexpr auto const & _2 = proto::utility::static_const>>::value; 85 | constexpr auto const & _3 = proto::utility::static_const>>::value; 86 | } 87 | 88 | static_assert(std::is_trivial>>::value, "_1 should be trivial"); 89 | BOOST_PROTO_IGNORE_UNUSED(_1, _2, _3); 90 | 91 | int main() 92 | { 93 | std::printf("*** \n"); 94 | std::printf("*** This program demonstrates how to build a lambda library with Proto.\n"); 95 | std::printf("*** \n"); 96 | 97 | // Create a lambda 98 | auto fun = _1 + 42 * _2; 99 | 100 | // pretty-print the expression 101 | proto::display_expr(fun); 102 | 103 | // Call the lambda 104 | int i = fun(8, 2); 105 | 106 | // print the result 107 | std::printf("The lambda '_1 + 42 * _2' yields '%d' when called with 8 and 2.\n", i); 108 | } 109 | -------------------------------------------------------------------------------- /libs/proto/v5/example/map_list_of.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // map_list_of.cpp 3 | // Implement the map_list_of utility from Boost.Assign. 4 | // 5 | // Copyright 2013 Eric Niebler. Distributed under the Boost 6 | // Software License, Version 1.0. (See accompanying file 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | #include 11 | #include 12 | using namespace boost::proto; 13 | 14 | struct map_list_of_ {}; 15 | 16 | struct MapListOf : def< 17 | match( 18 | case_( terminal(map_list_of_), 19 | void() 20 | ), 21 | case_( function(MapListOf, terminal(_), terminal(_)), 22 | MapListOf(_child0), 23 | assign(subscript(_data, _value(_child1)), _value(_child2)) 24 | ) 25 | ) 26 | > {}; 27 | 28 | template 29 | struct map_list_of_expr 30 | : expr, domain<_,MapListOf>> 31 | { 32 | using expr, domain<_,MapListOf>>::expr; 33 | 34 | template< class K, class V, class C, class A> 35 | operator std::map () const 36 | { 37 | assert_matches(*this); 38 | std::map map; 39 | MapListOf()(*this, data = map); 40 | return map; 41 | } 42 | }; 43 | 44 | constexpr map_list_of_expr map_list_of{}; 45 | 46 | int main() 47 | { 48 | // Initialize a map with a list of key/value pairs 49 | std::map vals = map_list_of(1,2)(2,3)(3,4)(4,5)(5,6); 50 | 51 | // Print out the key/value pairs 52 | for(auto const &p : vals) 53 | { 54 | std::cout << p.first << " : " << p.second << std::endl; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /libs/proto/v5/scratch/Jamfile: -------------------------------------------------------------------------------- 1 | # (C) Copyright 2012: Eric Niebler 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | 5 | exe main 6 | : 7 | main.cpp 8 | ; 9 | -------------------------------------------------------------------------------- /libs/proto/v5/scratch/Makefile: -------------------------------------------------------------------------------- 1 | #CXX=C:\cygwin\usr\local\gcc-4.7\bin\g++ 2 | CXX="C:/cygwin/usr/local/clang-trunk/bin/clang++.exe" 3 | #CFLAGS=-c -Wall -O2 -DNDEBUG 4 | #CFLAGS=-c -O2 -DNDEBUG 5 | CFLAGS=-c -O0 6 | CXXFLAGS=-std=gnu++11 -I../../../.. -I/cygdrive/c/Users/eric/Code/boost/org/trunk 7 | LDFLAGS= 8 | SOURCES=./main.cpp 9 | OBJECTS=$(SOURCES:.cpp=.o) 10 | EXECUTABLE=proto 11 | 12 | all: $(SOURCES) $(EXECUTABLE) 13 | 14 | $(EXECUTABLE): $(OBJECTS) 15 | $(CXX) $(LDFLAGS) $(OBJECTS) -o $@ 16 | 17 | .cpp.o: 18 | $(CXX) $(CFLAGS) $(CXXFLAGS) $< -o $@ 19 | 20 | clean: 21 | rm -f $(OBJECTS) $(EXECUTABLE).exe 22 | -------------------------------------------------------------------------------- /libs/proto/v5/scratch/proto.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 11.00 3 | # Visual Studio 2010 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "proto", "proto.vcxproj", "{E6CA9F16-0C2A-46B3-A09B-B9F01ED72FFE}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {E6CA9F16-0C2A-46B3-A09B-B9F01ED72FFE}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {E6CA9F16-0C2A-46B3-A09B-B9F01ED72FFE}.Debug|Win32.Build.0 = Debug|Win32 14 | {E6CA9F16-0C2A-46B3-A09B-B9F01ED72FFE}.Release|Win32.ActiveCfg = Release|Win32 15 | {E6CA9F16-0C2A-46B3-A09B-B9F01ED72FFE}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /libs/proto/v5/test/Jamfile: -------------------------------------------------------------------------------- 1 | # (C) Copyright 2012: Eric Niebler 2 | # Distributed under the Boost Software License, Version 1.0. 3 | # (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | 5 | # bring in rules for testing 6 | import testing ; 7 | 8 | project 9 | : requirements 10 | /boost/test//boost_unit_test_framework 11 | static 12 | -Wno-multichar 13 | ; 14 | 15 | test-suite "proto" 16 | : 17 | [ run action.cpp ] 18 | [ run apply.cpp ] 19 | [ compile bug2407.cpp ] 20 | [ run common_domain.cpp ] 21 | [ run constrained_ops.cpp ] 22 | [ run cpp-next_bug.cpp ] 23 | [ run deep_copy.cpp ] 24 | [ compile def.cpp ] 25 | [ run display_expr.cpp ] 26 | [ run everything.cpp ] 27 | [ run everywhere.cpp ] 28 | [ run expr.cpp ] 29 | [ run external.cpp ] 30 | [ run flatten.cpp ] 31 | [ run fold.cpp ] 32 | [ run let.cpp ] 33 | [ run logical_ops.cpp ] 34 | [ run make.cpp ] 35 | [ run make_expr.cpp ] 36 | [ run matches.cpp ] 37 | [ run mem_fun.cpp ] 38 | [ run mpl.cpp ] 39 | [ run noinvoke.cpp ] 40 | [ run pack_expansion.cpp ] 41 | [ run passthru.cpp ] 42 | [ run protect.cpp ] 43 | [ run virtual_member.cpp ] 44 | ; 45 | -------------------------------------------------------------------------------- /libs/proto/v5/test/action.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // action.cpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include 11 | #include "./unit_test.hpp" 12 | 13 | namespace mpl = boost::mpl; 14 | namespace proto = boost::proto; 15 | using proto::_; 16 | 17 | using int_ = proto::literal; 18 | using string_ = proto::literal; 19 | 20 | struct scope_type 21 | : proto::env_tag 22 | { 23 | BOOST_PROTO_REGULAR_TRIVIAL_CLASS(scope_type); 24 | using proto::env_tag::operator=; 25 | }; 26 | 27 | namespace 28 | { 29 | constexpr auto const & scope = proto::utility::static_const::value; 30 | } 31 | 32 | void test_action() 33 | { 34 | int_ p(42); 35 | 36 | { 37 | int i = (proto::data = 42)(proto::data); 38 | BOOST_CHECK_EQUAL(i, 42); 39 | auto env = (proto::data = 42, scope = "hello", scope = "goodbye"); 40 | i = env(proto::data); 41 | char const *loc = env(scope); 42 | BOOST_CHECK_EQUAL(std::string(loc), std::string("goodbye")); 43 | 44 | // Look, ma! A basic_action! 45 | char const (&sz)[6] = proto::_data()(p, (proto::data = "hello")); 46 | BOOST_PROTO_IGNORE_UNUSED(sz); 47 | } 48 | 49 | { 50 | proto::def< 51 | proto::match( 52 | proto::case_(proto::terminal(int), proto::_int<42>) 53 | , proto::case_(proto::terminal(std::string), proto::_int<43>) 54 | ) 55 | > SimpleAction; 56 | 57 | int i = SimpleAction(int_(0)); 58 | BOOST_CHECK_EQUAL(i, 42); 59 | 60 | i = SimpleAction(string_("hello!")); 61 | BOOST_CHECK_EQUAL(i, 43); 62 | } 63 | 64 | // Check the pass-through basic_action 65 | using X = proto::terminal(int); 66 | proto::def()(p(p)); 67 | proto::def()(p(p, p)); 68 | proto::def()(p(p, p, p)); 69 | } 70 | 71 | template 72 | struct S 73 | {}; 74 | 75 | // To defeat an optimization within Proto, to better exercise the proper handling 76 | // of nested actions with different numbers of arguments. 77 | struct _my_expr 78 | : proto::basic_action<_my_expr> 79 | { 80 | template 81 | auto operator()(E && e, Rest &&...) const 82 | BOOST_PROTO_AUTO_RETURN( 83 | static_cast(e) 84 | ) 85 | }; 86 | 87 | void test_action_2() 88 | { 89 | proto::literal i{42}; 90 | S s0 = proto::def())>()(i, proto::empty_env(), 42); 91 | S s1 = proto::def())>()(i, proto::empty_env(), 42); 92 | S s2 = proto::def())>()(i, proto::empty_env(), 42); 93 | S s3 = proto::def())>()(i, proto::data = 55, 42); 94 | S s4 = proto::def())>()(i, proto::data = 55, 42); 95 | BOOST_PROTO_IGNORE_UNUSED(s0, s1, s2, s3, s4); 96 | } 97 | 98 | using namespace boost::unit_test; 99 | //////////////////////////////////////////////////////////////////////////////////////////////////// 100 | // init_unit_test_suite 101 | // 102 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 103 | { 104 | test_suite *test = BOOST_TEST_SUITE("basic tests for the action infrastructure"); 105 | 106 | test->add(BOOST_TEST_CASE(&test_action)); 107 | test->add(BOOST_TEST_CASE(&test_action_2)); 108 | 109 | return test; 110 | } 111 | -------------------------------------------------------------------------------- /libs/proto/v5/test/apply.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // apply.cpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include "./unit_test.hpp" 11 | 12 | namespace proto = boost::proto; 13 | using proto::_; 14 | 15 | template 16 | struct fN 17 | : proto::env_tag> 18 | { 19 | BOOST_PROTO_REGULAR_TRIVIAL_CLASS(fN); 20 | using proto::env_tag::operator=; 21 | }; 22 | 23 | namespace 24 | { 25 | constexpr auto const & _f0 = proto::utility::static_const>::value; 26 | constexpr auto const & _f1 = proto::utility::static_const>::value; 27 | } 28 | 29 | struct eval_unpack 30 | : proto::def< 31 | proto::apply( 32 | proto::get_env(fN<0>()) 33 | , proto::apply(proto::get_env(fN<1>()), proto::pack(_))... 34 | ) 35 | > 36 | {}; 37 | 38 | template 39 | auto unpack(E && e, F0 && f0, F1 && f1) 40 | BOOST_PROTO_AUTO_RETURN( 41 | eval_unpack()( 42 | std::forward(e) 43 | , (_f0 = std::forward(f0), _f1 = std::forward(f1)) 44 | ) 45 | ) 46 | 47 | struct square 48 | { 49 | template 50 | T operator()(T t) const 51 | { 52 | return t * t; 53 | } 54 | }; 55 | 56 | struct sum 57 | { 58 | template 59 | T operator()(T t) const 60 | { 61 | return t; 62 | } 63 | 64 | template 65 | T operator()(T t, U ...u) const 66 | { 67 | return t + (*this)(u...); 68 | } 69 | }; 70 | 71 | void test_apply() 72 | { 73 | proto::literal i{0}; 74 | 75 | // 0^2 + 1^2 + 2^2 + 3^2 = 0+1+4+9 = 14 76 | proto::def square_; 77 | int sum_of_squares = unpack(i(1,2,3), sum(), square_); 78 | BOOST_CHECK_EQUAL(sum_of_squares, 14); 79 | } 80 | 81 | using namespace boost::unit_test; 82 | //////////////////////////////////////////////////////////////////////////////////////////////////// 83 | // init_unit_test_suite 84 | // 85 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 86 | { 87 | test_suite *test = BOOST_TEST_SUITE("tests for proto::apply"); 88 | 89 | test->add(BOOST_TEST_CASE(&test_apply)); 90 | 91 | return test; 92 | } 93 | -------------------------------------------------------------------------------- /libs/proto/v5/test/bug2407.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // bug2407.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | 11 | namespace mpl = boost::mpl; 12 | namespace proto = boost::proto; 13 | using proto::_; 14 | 15 | struct g 16 | : proto::def< 17 | proto::match( 18 | proto::terminal(int) 19 | , proto::plus(g, g) 20 | ) 21 | > 22 | {}; 23 | 24 | struct d 25 | : proto::domain 26 | {}; 27 | 28 | template 29 | struct e 30 | : proto::basic_expr, d> 31 | { 32 | static_assert(proto::matches, g>(), ""); 33 | using proto::basic_expr::basic_expr; 34 | }; 35 | 36 | e i; 37 | 38 | template 39 | std::ostream &operator<<(std::ostream &sout, e const &x) 40 | { 41 | return sout; 42 | } 43 | 44 | int main() 45 | { 46 | std::cout << (i+i); 47 | } 48 | -------------------------------------------------------------------------------- /libs/proto/v5/test/constrained_ops.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // constrained_ops.cpp 3 | // 4 | // Copyright 2010 Thomas Heller 5 | // Copyright 2012 Eric Niebler 6 | // 7 | // Distributed under the Boost Software License, Version 1.0. (See accompanying 8 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 9 | 10 | #include 11 | #include 12 | #include "./unit_test.hpp" 13 | 14 | using namespace boost; 15 | 16 | using term = proto::literal; 17 | 18 | struct addition: 19 | proto::def< 20 | proto::match( 21 | proto::terminal(proto::_) 22 | , proto::plus(addition, addition) 23 | ) 24 | > 25 | {}; 26 | 27 | struct equation: 28 | proto::def< 29 | proto::equal_to(addition, addition) 30 | > 31 | {}; 32 | 33 | template 34 | struct extension; 35 | 36 | struct my_domain: 37 | proto::domain< 38 | my_domain, 39 | equation, 40 | proto::default_domain 41 | > 42 | { 43 | using make_expr = proto::make_custom_expr>; 44 | }; 45 | 46 | template 47 | struct lhs_extension; 48 | 49 | struct my_lhs_domain: 50 | proto::domain< 51 | my_lhs_domain, 52 | addition, 53 | my_domain 54 | > 55 | { 56 | using make_expr = proto::make_custom_expr>; 57 | }; 58 | 59 | template 60 | struct rhs_extension; 61 | 62 | struct my_rhs_domain: 63 | proto::domain< 64 | my_rhs_domain, 65 | addition, 66 | my_domain 67 | > 68 | { 69 | using make_expr = proto::make_custom_expr>; 70 | }; 71 | 72 | template 73 | struct extension 74 | : proto::basic_expr 75 | { 76 | using proto_domain_type = my_domain; 77 | using proto::basic_expr::basic_expr; 78 | 79 | void test() const 80 | {} 81 | }; 82 | 83 | template 84 | struct lhs_extension 85 | : proto::basic_expr 86 | { 87 | using proto_domain_type = my_lhs_domain; 88 | using proto::basic_expr::basic_expr; 89 | }; 90 | 91 | template 92 | struct rhs_extension 93 | : proto::basic_expr 94 | { 95 | using proto_domain_type = my_rhs_domain; 96 | using proto::basic_expr::basic_expr; 97 | }; 98 | 99 | void test_constrained_ops() 100 | { 101 | lhs_extension const i {0}; 102 | rhs_extension const j {0}; 103 | 104 | proto::assert_matches_not(i); // false 105 | proto::assert_matches_not(j); // false 106 | proto::assert_matches_not(i + i); // false 107 | proto::assert_matches_not(j + j); // false 108 | #if 0 109 | proto::assert_matches_not(i + j); // compile error (by design) 110 | proto::assert_matches_not(j + i); // compile error (by design) 111 | #endif 112 | proto::assert_matches(i == j); // true 113 | proto::assert_matches(i == j + j); // true 114 | proto::assert_matches(i + i == j); // true 115 | proto::assert_matches(i + i == j + j); // true 116 | } 117 | 118 | using namespace boost::unit_test; 119 | //////////////////////////////////////////////////////////////////////////////////////////////////// 120 | // init_unit_test_suite 121 | // 122 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 123 | { 124 | test_suite *test = BOOST_TEST_SUITE("test constrained EDSLs"); 125 | test->add(BOOST_TEST_CASE(&test_constrained_ops)); 126 | return test; 127 | } 128 | -------------------------------------------------------------------------------- /libs/proto/v5/test/cpp-next_bug.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // cpp-next_bug.hpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include 11 | #include "./unit_test.hpp" 12 | namespace mpl = boost::mpl; 13 | namespace proto = boost::proto; 14 | using proto::_; 15 | 16 | namespace linear_algebra 17 | { 18 | // A trait that returns true only for std::vector 19 | template 20 | struct is_std_vector 21 | : mpl::false_ 22 | {}; 23 | 24 | template 25 | struct is_std_vector > 26 | : mpl::true_ 27 | {}; 28 | 29 | // A type used as a domain for linear algebra expressions 30 | struct linear_algebra_domain 31 | : proto::domain 32 | { 33 | using make_expr = proto::make_custom_expr>; 34 | }; 35 | 36 | // Define all the operator overloads for combining std::vectors 37 | #define BOOST_PROTO_OPERATOR_TRAITS (is_std_vector, linear_algebra_domain) 38 | #include BOOST_PROTO_DEFINE_OPERATORS() 39 | 40 | // Take any expression and turn each node 41 | // into a subscript expression, using the 42 | // state as the RHS. 43 | struct Distribute 44 | : proto::def< 45 | proto::match( 46 | proto::case_( 47 | proto::terminal(_) 48 | , proto::subscript(_, proto::_state) 49 | ) 50 | , proto::case_( 51 | proto::plus(Distribute, Distribute) 52 | , proto::passthru 53 | ) 54 | ) 55 | > 56 | {}; 57 | 58 | struct Optimize 59 | : proto::def< 60 | proto::match( 61 | proto::case_( 62 | proto::subscript(Distribute, proto::terminal(_)) 63 | , Distribute(proto::_left, proto::empty_env(), proto::_right) 64 | ) 65 | , proto::case_( 66 | proto::plus(Optimize, Optimize) 67 | , proto::passthru 68 | ) 69 | , proto::case_( 70 | proto::terminal(_) 71 | , proto::passthru 72 | ) 73 | ) 74 | > 75 | {}; 76 | } 77 | 78 | static constexpr int celems = 4; 79 | static constexpr int value[celems] = {1,2,3,4}; 80 | std::vector A(value, value+celems), B(A); 81 | 82 | void test1() 83 | { 84 | using namespace linear_algebra; 85 | proto::_eval eval; 86 | int result = eval(Optimize()((A + B)[3])); 87 | proto::assert_matches((A + B)[3]); 88 | proto::assert_matches_not((A - B)[3]); 89 | BOOST_CHECK_EQUAL(8, result); 90 | } 91 | 92 | using namespace boost::unit_test; 93 | //////////////////////////////////////////////////////////////////////////////////////////////////// 94 | // init_unit_test_suite 95 | // 96 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 97 | { 98 | test_suite *test = BOOST_TEST_SUITE("test for a problem reported on the cpp-next.com blog"); 99 | 100 | test->add(BOOST_TEST_CASE(&test1)); 101 | 102 | return test; 103 | } 104 | -------------------------------------------------------------------------------- /libs/proto/v5/test/def.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // def.cpp 3 | // 4 | // Copyright 2013 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | 10 | namespace proto = boost::proto; 11 | using proto::_; 12 | 13 | struct Grammar 14 | : proto::def< 15 | proto::match( 16 | proto::terminal(int) 17 | , proto::plus(Grammar, Grammar) 18 | ) 19 | > 20 | {}; 21 | 22 | static_assert(proto::is_grammar::value, ""); 23 | static_assert(!proto::is_action::value, ""); 24 | 25 | static_assert(proto::is_grammar::value, ""); 26 | static_assert(!proto::is_action::value, ""); 27 | 28 | struct GrammarAndAction 29 | : proto::def< 30 | proto::match( 31 | proto::case_(proto::terminal(int), proto::passthru) 32 | , proto::case_(proto::plus(Grammar, Grammar), proto::passthru) 33 | ) 34 | > 35 | {}; 36 | 37 | static_assert(proto::is_grammar::value, ""); 38 | static_assert(proto::is_action::value, ""); 39 | 40 | static_assert(proto::is_grammar::value, ""); 41 | static_assert(proto::is_action::value, ""); 42 | 43 | struct Action 44 | : proto::def< 45 | proto::fold(_, int(), proto::_state) 46 | > 47 | {}; 48 | 49 | static_assert(!proto::is_grammar::value, ""); 50 | static_assert(proto::is_action::value, ""); 51 | 52 | static_assert(!proto::is_grammar::value, ""); 53 | static_assert(proto::is_action::value, ""); 54 | 55 | static_assert(proto::is_grammar<_>::value, ""); 56 | static_assert(proto::is_action<_>::value, ""); 57 | 58 | struct foo 59 | {}; 60 | 61 | static_assert(!proto::is_grammar::value, ""); 62 | static_assert(!proto::is_action::value, ""); 63 | -------------------------------------------------------------------------------- /libs/proto/v5/test/display_expr.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // display_expr.cpp 3 | // 4 | // Copyright 2010 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include 11 | #include "./unit_test.hpp" 12 | 13 | namespace mpl = boost::mpl; 14 | namespace proto = boost::proto; 15 | using proto::_; 16 | 17 | struct A {}; 18 | struct B : A {}; 19 | std::ostream& operator<<( std::ostream& out, const A& ) { return out << "this is A!"; } 20 | 21 | struct C {}; 22 | 23 | void test_display_expr() 24 | { 25 | // https://svn.boost.org/trac/boost/ticket/4910 26 | proto::literal i{0}; 27 | std::string intname = proto::detail::name_of(); 28 | 29 | { 30 | std::stringstream sout; 31 | proto::display_expr(i + A(), sout); 32 | std::string Aname = proto::detail::name_of(); 33 | BOOST_CHECK_EQUAL(sout.str(), std::string( 34 | "plus(\n" 35 | " terminal( (int) 0 ) &\n" 36 | " , terminal( (" + Aname + ") this is A! )\n" 37 | ")\n")); 38 | } 39 | 40 | { 41 | std::stringstream sout; 42 | proto::display_expr(i + B(), sout); 43 | std::string Bname = proto::detail::name_of(); 44 | BOOST_CHECK_EQUAL(sout.str(), std::string( 45 | "plus(\n" 46 | " terminal( (" + intname + ") 0 ) &\n" 47 | " , terminal( (" + Bname + ") this is A! )\n" 48 | ")\n")); 49 | } 50 | 51 | { 52 | std::stringstream sout; 53 | std::string Cname = proto::detail::name_of(); 54 | proto::display_expr(i + C(), sout); 55 | BOOST_CHECK_EQUAL(sout.str(), std::string( 56 | "plus(\n" 57 | " terminal( (" + intname + ") 0 ) &\n" 58 | " , terminal( (" + Cname + ") " + Cname + " )\n" 59 | ")\n")); 60 | } 61 | } 62 | 63 | using namespace boost::unit_test; 64 | //////////////////////////////////////////////////////////////////////////////////////////////////// 65 | // init_unit_test_suite 66 | // 67 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 68 | { 69 | test_suite *test = BOOST_TEST_SUITE("test display_expr() function"); 70 | test->add(BOOST_TEST_CASE(&test_display_expr)); 71 | return test; 72 | } 73 | -------------------------------------------------------------------------------- /libs/proto/v5/test/everything.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // everything.cpp 3 | // 4 | // Copyright 2013 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./unit_test.hpp" 10 | 11 | namespace proto = boost::proto; 12 | using proto::_; 13 | 14 | struct map_list_of_ 15 | {}; 16 | 17 | constexpr proto::expr map_list_of {}; 18 | 19 | namespace Impl 20 | { 21 | using namespace proto; 22 | struct Sum 23 | : def< 24 | everything( 25 | plus 26 | , match( case_(terminal(int), _value) 27 | , case_(terminal(map_list_of_), _int<100>) 28 | ) 29 | ) 30 | > 31 | {}; 32 | } 33 | using Impl::Sum; 34 | 35 | void test_everything() 36 | { 37 | int sum = Sum()(map_list_of(1,2)(2,3)(3,4)(4,5)(5,6)); 38 | BOOST_CHECK_EQUAL(sum, 135); 39 | 40 | using namespace proto::literals; 41 | proto::nothing nil_ = Sum()("hello"_et + 3.14); 42 | BOOST_PROTO_IGNORE_UNUSED(nil_); 43 | } 44 | 45 | using namespace boost::unit_test; 46 | //////////////////////////////////////////////////////////////////////////////////////////////////// 47 | // init_unit_test_suite 48 | // 49 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 50 | { 51 | test_suite *test = BOOST_TEST_SUITE("testing the everything action"); 52 | 53 | test->add(BOOST_TEST_CASE(&test_everything)); 54 | 55 | return test; 56 | } 57 | -------------------------------------------------------------------------------- /libs/proto/v5/test/everywhere.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // everywhere.cpp 3 | // 4 | // Copyright 2013 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include "./unit_test.hpp" 10 | 11 | namespace proto = boost::proto; 12 | using proto::_; 13 | 14 | struct S_ {}; 15 | constexpr proto::expr S {}; 16 | constexpr auto omg = S(1,2)(2,3); 17 | 18 | struct Square 19 | : proto::def< 20 | proto::everywhere( 21 | proto::case_( 22 | proto::terminal(int), 23 | proto::terminal(proto::multiplies(proto::_value, proto::_value)) 24 | ) 25 | ) 26 | > 27 | {}; 28 | 29 | using X = proto::custom>; 30 | constexpr X::function< 31 | X::function< 32 | X::terminal 33 | , X::terminal 34 | , X::terminal 35 | > 36 | , X::terminal 37 | , X::terminal 38 | > omg_wtf = Square()(omg); 39 | 40 | static_assert(proto::value(proto::child<2>(proto::child<0>(omg_wtf)))==4, "oops"); 41 | 42 | struct Flip 43 | : proto::def< 44 | proto::everywhere( 45 | proto::case_( 46 | proto::plus(_,_) 47 | , proto::minus(proto::_left, proto::_right) 48 | ) 49 | , proto::case_( 50 | proto::minus(_,_) 51 | , proto::plus(proto::_left, proto::_right) 52 | ) 53 | ) 54 | > 55 | {}; 56 | 57 | void test_everywhere() 58 | { 59 | using namespace proto::literals; 60 | 61 | proto::expr< 62 | proto::plus( 63 | proto::minus( 64 | proto::plus( 65 | proto::terminal(unsigned long long) 66 | , proto::terminal(unsigned long long) 67 | ) 68 | , proto::plus( 69 | proto::terminal(unsigned long long) 70 | , proto::terminal(unsigned long long) 71 | ) 72 | ) 73 | , proto::minus( 74 | proto::plus( 75 | proto::terminal(unsigned long long) 76 | , proto::terminal(unsigned long long) 77 | ) 78 | , proto::plus( 79 | proto::terminal(unsigned long long) 80 | , proto::terminal(unsigned long long) 81 | ) 82 | ) 83 | ) 84 | > y = ((1_et + 1_et) - (1_et + 1_et)) + ((1_et + 1_et) - (1_et + 1_et)); 85 | 86 | 87 | proto::expr< 88 | proto::minus( 89 | proto::plus( 90 | proto::minus( 91 | proto::terminal(unsigned long long) 92 | , proto::terminal(unsigned long long) 93 | ) 94 | , proto::minus( 95 | proto::terminal(unsigned long long) 96 | , proto::terminal(unsigned long long) 97 | ) 98 | ) 99 | , proto::plus( 100 | proto::minus( 101 | proto::terminal(unsigned long long) 102 | , proto::terminal(unsigned long long) 103 | ) 104 | , proto::minus( 105 | proto::terminal(unsigned long long) 106 | , proto::terminal(unsigned long long) 107 | ) 108 | ) 109 | ) 110 | > z = Flip()(y); 111 | 112 | BOOST_CHECK_EQUAL( 113 | proto::value(proto::left(proto::left(proto::left(z)))) 114 | , 1 115 | ); 116 | } 117 | 118 | using namespace boost::unit_test; 119 | //////////////////////////////////////////////////////////////////////////////////////////////////// 120 | // init_unit_test_suite 121 | // 122 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 123 | { 124 | test_suite *test = BOOST_TEST_SUITE("testing the everywhere action"); 125 | 126 | test->add(BOOST_TEST_CASE(&test_everywhere)); 127 | 128 | return test; 129 | } 130 | -------------------------------------------------------------------------------- /libs/proto/v5/test/external.cpp: -------------------------------------------------------------------------------- 1 | // Copyright 2013 Eric Niebler. Distributed under the Boost 2 | // Software License, Version 1.0. (See accompanying file 3 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 4 | // 5 | // This is an example of how to specify an action externally so 6 | // that a single grammar can be used to drive multiple differnt 7 | // calculations. In particular, it defines a calculator grammar 8 | // that computes the result of an expression with either checked 9 | // or non-checked division. 10 | 11 | #include 12 | #include 13 | #include 14 | #include "./unit_test.hpp" 15 | 16 | namespace mpl = boost::mpl; 17 | namespace proto = boost::proto; 18 | namespace fusion = boost::fusion; 19 | using proto::_; 20 | 21 | // The argument placeholder type 22 | template 23 | struct placeholder 24 | : I, proto::env_tag> 25 | { 26 | using proto::env_tag>::operator=; 27 | }; 28 | 29 | // Give each rule in the grammar a "name". This is so that we 30 | // can easily dispatch on it later. 31 | struct calc_grammar; 32 | struct divides_rule 33 | : proto::def 34 | , proto::env_tag 35 | { 36 | using proto::env_tag::operator=; 37 | }; 38 | 39 | // Use external transforms in calc_gramar 40 | struct calc_grammar 41 | : proto::def< 42 | proto::match( 43 | proto::case_( 44 | proto::terminal(placeholder<_>) 45 | , proto::get_env(proto::_value) 46 | ) 47 | , proto::case_( 48 | proto::terminal(proto::convertible_to) 49 | , proto::_value 50 | ) 51 | , proto::case_( 52 | proto::plus(calc_grammar, calc_grammar) 53 | , proto::eval_with(calc_grammar) 54 | ) 55 | , proto::case_( 56 | proto::minus(calc_grammar, calc_grammar) 57 | , proto::eval_with(calc_grammar) 58 | ) 59 | , proto::case_( 60 | proto::multiplies(calc_grammar, calc_grammar) 61 | , proto::eval_with(calc_grammar) 62 | ) 63 | // Note that we don't specify how division nodes are 64 | // handled here. proto::external is a placeholder 65 | // for an actual action. 66 | , proto::case_( 67 | divides_rule 68 | , proto::external 69 | ) 70 | ) 71 | > 72 | {}; 73 | 74 | template 75 | struct calc_expr 76 | : proto::expr> 77 | { 78 | using proto::expr>::expr; 79 | }; 80 | 81 | constexpr calc_expr>)> _1 {}; 82 | constexpr calc_expr>)> _2 {}; 83 | 84 | struct non_checked_division 85 | : proto::def 86 | {}; 87 | 88 | struct division_by_zero 89 | : std::exception 90 | {}; 91 | 92 | struct do_checked_divide 93 | { 94 | int operator()(int left, int right) const 95 | { 96 | if (right == 0) throw division_by_zero(); 97 | return left / right; 98 | } 99 | }; 100 | 101 | // Use proto::external_transforms again, this time to map the divides_rule 102 | // to a transforms that performs checked division. 103 | struct checked_division 104 | : proto::def 105 | {}; 106 | 107 | void test_external_actions() 108 | { 109 | placeholder> _1_; // BUGBUG would be nice to just say _1 = 2; 110 | placeholder> _2_; 111 | int result1 = calc_grammar()(_1 / _2, (_1_ = 6, _2_ = 2, divides_rule() = non_checked_division())); 112 | BOOST_CHECK_EQUAL(result1, 3); 113 | 114 | try 115 | { 116 | // This should throw 117 | int result2 = calc_grammar()(_1 / _2, (_1_ = 6, _2_ = 0, divides_rule() = checked_division())); 118 | BOOST_PROTO_IGNORE_UNUSED(result2); 119 | BOOST_CHECK(!"Didn't throw an exception"); // shouldn't get here! 120 | } 121 | catch(division_by_zero) 122 | { 123 | ; // OK 124 | } 125 | catch(...) 126 | { 127 | BOOST_CHECK(!"Unexpected exception"); // shouldn't get here! 128 | } 129 | } 130 | 131 | using namespace boost::unit_test; 132 | /////////////////////////////////////////////////////////////////////////////// 133 | // init_unit_test_suite 134 | // 135 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 136 | { 137 | test_suite *test = BOOST_TEST_SUITE("test for external actions"); 138 | 139 | test->add(BOOST_TEST_CASE(&test_external_actions)); 140 | 141 | return test; 142 | } 143 | -------------------------------------------------------------------------------- /libs/proto/v5/test/fold.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // fold.cpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include "./unit_test.hpp" 15 | 16 | namespace mpl = boost::mpl; 17 | namespace fusion = boost::fusion; 18 | namespace proto = boost::proto; 19 | using proto::_; 20 | 21 | template 22 | struct placeholder 23 | : Int 24 | {}; 25 | 26 | namespace 27 | { 28 | constexpr auto const & _1 = proto::utility::static_const>>>::value; 29 | constexpr auto const & _2 = proto::utility::static_const>>>::value; 30 | constexpr auto const & _3 = proto::utility::static_const>>>::value; 31 | } 32 | 33 | BOOST_PROTO_IGNORE_UNUSED(_1, _2, _3); 34 | 35 | // The lambda grammar, with the transforms for calculating the max arity 36 | template 37 | struct lambda_arity 38 | : proto::def< 39 | proto::if_( 40 | proto::matches_( proto::terminal( placeholder<_> ) ) 41 | , proto::make( mpl::next< proto::_value >() ) 42 | , proto::if_( 43 | proto::matches_( proto::terminal(_) ) 44 | , mpl::int_<0>() 45 | , Fold( 46 | _ 47 | , mpl::int_<0>() 48 | , proto::make( mpl::max, proto::_state>() ) 49 | ) 50 | ) 51 | ) 52 | > 53 | {}; 54 | 55 | void test_fold() 56 | { 57 | auto result0 = lambda_arity()(proto::literal(42) + 36); 58 | static_assert(decltype(result0)::value == 0, ""); 59 | 60 | auto result1 = lambda_arity()(proto::literal(42) + _1); 61 | static_assert(decltype(result1)::value == 1, ""); 62 | 63 | auto result2 = lambda_arity()(_2 + _1); 64 | static_assert(decltype(result2)::value == 2, ""); 65 | 66 | auto result3 = lambda_arity()(_2 + _1 * _3); 67 | static_assert(decltype(result3)::value == 3, ""); 68 | } 69 | 70 | void test_reverse_fold() 71 | { 72 | auto result0 = lambda_arity()(proto::literal(42) + 36); 73 | static_assert(decltype(result0)::value == 0, ""); 74 | 75 | auto result1 = lambda_arity()(proto::literal(42) + _1); 76 | static_assert(decltype(result1)::value == 1, ""); 77 | 78 | auto result2 = lambda_arity()(_2 + _1); 79 | static_assert(decltype(result2)::value == 2, ""); 80 | 81 | auto result3 = lambda_arity()(_2 + _1 * _3); 82 | static_assert(decltype(result3)::value == 3, ""); 83 | } 84 | 85 | using fusion::nil; 86 | using fusion::cons; 87 | 88 | template 89 | struct to_cons_list 90 | : proto::def< 91 | RecursiveFold( 92 | _ 93 | , nil() 94 | , proto::make( cons(proto::_value, proto::_state) ) 95 | ) 96 | > 97 | {}; 98 | 99 | void test_recursive_fold() 100 | { 101 | cons>> list0 = 102 | to_cons_list()( proto::literal(42) >> "hello" >> 'a' ); 103 | 104 | BOOST_CHECK_EQUAL(list0.car, 'a'); 105 | BOOST_CHECK_EQUAL(std::strcmp(list0.cdr.car, "hello"), 0); 106 | BOOST_CHECK_EQUAL(list0.cdr.cdr.car, 42); 107 | } 108 | 109 | void test_reverse_recursive_fold() 110 | { 111 | cons>> list0 = 112 | to_cons_list()( proto::literal(42) >> "hello" >> 'a' ); 113 | 114 | BOOST_CHECK_EQUAL(list0.car, 42); 115 | BOOST_CHECK_EQUAL(std::strcmp(list0.cdr.car, "hello"), 0); 116 | BOOST_CHECK_EQUAL(list0.cdr.cdr.car, 'a'); 117 | } 118 | 119 | using namespace boost::unit_test; 120 | //////////////////////////////////////////////////////////////////////////////////////////////////// 121 | // init_unit_test_suite 122 | // 123 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 124 | { 125 | test_suite *test = BOOST_TEST_SUITE("test fold algorithms"); 126 | 127 | test->add(BOOST_TEST_CASE(&test_fold)); 128 | test->add(BOOST_TEST_CASE(&test_reverse_fold)); 129 | test->add(BOOST_TEST_CASE(&test_recursive_fold)); 130 | test->add(BOOST_TEST_CASE(&test_reverse_recursive_fold)); 131 | 132 | return test; 133 | } 134 | -------------------------------------------------------------------------------- /libs/proto/v5/test/let.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // let.cpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include "./unit_test.hpp" 11 | 12 | namespace proto = boost::proto; 13 | using proto::_; 14 | using proto::_a; 15 | using proto::_b; 16 | 17 | //////////////////////////////////////////////////////////////////////////////////////////////////// 18 | // test_let_call_once 19 | // verify that the transform bound to the local variable is really called 20 | // only once. 21 | struct once 22 | { 23 | static int ctors; 24 | once() { ++ctors; } 25 | }; 26 | 27 | int once::ctors = 0; 28 | 29 | struct LetCallOnce 30 | : proto::def< 31 | proto::let( 32 | _a(once()) 33 | , proto::functional::std::make_pair(_a, _a) 34 | ) 35 | > 36 | {}; 37 | 38 | void test_let_call_once() 39 | { 40 | proto::literal i(0); 41 | std::pair p = LetCallOnce()(i); 42 | BOOST_CHECK_EQUAL(1, once::ctors); 43 | } 44 | 45 | //////////////////////////////////////////////////////////////////////////////////////////////////// 46 | // test_let_make_action 47 | // verify that let works with object transforms. 48 | struct LetMakeAction 49 | : proto::def< 50 | proto::let( 51 | _a(proto::_int<42>) 52 | , proto::make(std::pair<_a, _a>(_a, _a)) 53 | ) 54 | > 55 | {}; 56 | 57 | void test_let_make_action() 58 | { 59 | proto::literal i(0); 60 | std::pair p = LetMakeAction()(i); 61 | BOOST_CHECK_EQUAL(42, p.first); 62 | BOOST_CHECK_EQUAL(42, p.second); 63 | } 64 | 65 | //////////////////////////////////////////////////////////////////////////////////////////////////// 66 | // test_let_data 67 | // verify that data doesn't get nuked. 68 | struct MyData 69 | : proto::_data 70 | {}; 71 | 72 | struct LetData 73 | : proto::def< 74 | proto::let( 75 | _a(proto::_int<42>) 76 | , proto::make(std::pair(MyData, _a)) 77 | ) 78 | > 79 | {}; 80 | 81 | void test_let_data() 82 | { 83 | std::string hello("hello"); 84 | proto::literal i(0); 85 | std::pair p = LetData()(i, proto::data = hello); 86 | BOOST_CHECK_EQUAL(hello, p.first); 87 | BOOST_CHECK_EQUAL(42, p.second); 88 | } 89 | 90 | //////////////////////////////////////////////////////////////////////////////////////////////////// 91 | // test_let_scope 92 | // verify that the local variables are scoped properly. 93 | struct LetScope 94 | : proto::def< 95 | proto::let( 96 | _a(proto::_value) 97 | , proto::functional::std::make_pair( 98 | _a 99 | , proto::let( 100 | _a(proto::_state) 101 | , proto::functional::std::make_pair(_a, proto::_data) 102 | ) 103 | ) 104 | ) 105 | > 106 | {}; 107 | 108 | void test_let_scope() 109 | { 110 | std::string hello("hello"); 111 | proto::literal i((short)42); 112 | std::pair> p = LetScope()(i, proto::data = hello, 3.14f); 113 | BOOST_CHECK_EQUAL(42, p.first); 114 | BOOST_CHECK_EQUAL(3.14f, p.second.first); 115 | BOOST_CHECK_EQUAL(hello, p.second.second); 116 | } 117 | 118 | //////////////////////////////////////////////////////////////////////////////////////////////////// 119 | // test_let_scope2 120 | // verify that the local variables are scoped properly. 121 | struct LetScope2 122 | : proto::def< 123 | proto::let( 124 | _a(proto::_value) 125 | , proto::functional::std::make_pair( 126 | _a 127 | , proto::let( 128 | _b(proto::_state) 129 | , proto::functional::std::make_pair(_a, _b) 130 | ) 131 | ) 132 | ) 133 | > 134 | {}; 135 | 136 | void test_let_scope2() 137 | { 138 | char const * sz = ""; 139 | proto::literal i((short)42); 140 | std::pair> p2 = LetScope2()(i, proto::data = sz, 3.14f); 141 | BOOST_CHECK_EQUAL(42, p2.first); 142 | BOOST_CHECK_EQUAL(42, p2.second.first); 143 | BOOST_CHECK_EQUAL(3.14f, p2.second.second); 144 | } 145 | 146 | using namespace boost::unit_test; 147 | //////////////////////////////////////////////////////////////////////////////////////////////////// 148 | // init_unit_test_suite 149 | // 150 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 151 | { 152 | test_suite *test = BOOST_TEST_SUITE("test let basic action"); 153 | 154 | test->add(BOOST_TEST_CASE(&test_let_call_once)); 155 | test->add(BOOST_TEST_CASE(&test_let_make_action)); 156 | test->add(BOOST_TEST_CASE(&test_let_data)); 157 | test->add(BOOST_TEST_CASE(&test_let_scope)); 158 | test->add(BOOST_TEST_CASE(&test_let_scope2)); 159 | 160 | return test; 161 | } 162 | -------------------------------------------------------------------------------- /libs/proto/v5/test/make.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // make.cpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include "./unit_test.hpp" 11 | 12 | namespace mpl = boost::mpl; 13 | namespace proto = boost::proto; 14 | using proto::_; 15 | 16 | namespace test_make 17 | { 18 | template 19 | struct type2type {}; 20 | 21 | template 22 | struct wrapper 23 | { 24 | T t_; 25 | explicit wrapper(T const & t = T()) : t_(t) {} 26 | }; 27 | 28 | template 29 | struct careful 30 | { 31 | using not_there = typename T::not_there; 32 | }; 33 | 34 | // Test that when no substitution is done, we don't instantiate templates 35 | struct MakeTest1 36 | : proto::def< proto::make( type2type< careful >() ) > 37 | {}; 38 | 39 | struct MakeTest1prime 40 | : proto::def< type2type< careful >() > 41 | {}; 42 | 43 | void make_test1() 44 | { 45 | proto::literal i{42}; 46 | type2type< careful > res = MakeTest1()(i); 47 | type2type< careful > res2 = MakeTest1prime()(i); 48 | BOOST_PROTO_IGNORE_UNUSED(res, res2); 49 | } 50 | 51 | // Test that when substitution is done, and there is no nested ::type 52 | // typedef, the result is the wrapper 53 | struct MakeTest2 54 | : proto::def< proto::make( wrapper< proto::_value >() ) > 55 | {}; 56 | 57 | void make_test2() 58 | { 59 | proto::literal i{42}; 60 | wrapper res = MakeTest2()(i); 61 | BOOST_CHECK_EQUAL(res.t_, 0); 62 | } 63 | 64 | // Test that when substitution is done, and there is no nested ::type 65 | // typedef, the result is the wrapper 66 | struct MakeTest3 67 | : proto::def< proto::make( wrapper< proto::_value >(proto::_value) ) > 68 | {}; 69 | 70 | void make_test3() 71 | { 72 | proto::literal i{42}; 73 | wrapper res = MakeTest3()(i); 74 | BOOST_CHECK_EQUAL(res.t_, 42); 75 | } 76 | 77 | // Test that when substitution is done, and there is a nested ::type 78 | // typedef, the result is that type. 79 | struct MakeTest4 80 | : proto::def< proto::make( mpl::identity< proto::_value >(proto::_value) ) > 81 | {}; 82 | 83 | void make_test4() 84 | { 85 | proto::literal i{42}; 86 | int res = MakeTest4()(i); 87 | BOOST_CHECK_EQUAL(res, 42); 88 | } 89 | 90 | struct MakeTest5 91 | : proto::def< proto::make( wrapper< proto::_state(_, proto::_env, proto::_state) >(proto::_state(_)) ) > 92 | {}; 93 | 94 | void make_test5() 95 | { 96 | proto::literal i{42}; 97 | wrapper res = MakeTest5()(i, proto::empty_env(), 43); 98 | BOOST_CHECK_EQUAL(res.t_, 43); 99 | } 100 | 101 | using proto::utility::identity; 102 | struct MakeTest6 103 | : proto::def< proto::make( wrapper< identity(proto::_state) >(proto::_state(_)) ) > 104 | {}; 105 | 106 | void make_test6() 107 | { 108 | proto::literal i{42}; 109 | wrapper res = MakeTest6()(i, proto::empty_env(), 43); 110 | BOOST_CHECK_EQUAL(res.t_, 43); 111 | } 112 | 113 | struct MakeTest7 114 | : proto::def< proto::make( wrapper< proto::make( int(proto::_state) ) >(proto::_state(_)) ) > 115 | {}; 116 | 117 | struct MakeTest7prime 118 | : proto::def< proto::make( wrapper< int(proto::_state) >(proto::_state(_)) ) > 119 | {}; 120 | 121 | void make_test7() 122 | { 123 | proto::literal i{42}; 124 | wrapper res = MakeTest7()(i, proto::empty_env(), 43); 125 | BOOST_CHECK_EQUAL(res.t_, 43); 126 | wrapper res2 = MakeTest7prime()(i, proto::empty_env(), 44); 127 | BOOST_CHECK_EQUAL(res2.t_, 44); 128 | } 129 | 130 | struct tfx : proto::basic_action 131 | { 132 | template 133 | auto operator()(E && e, T &&... t) const 134 | BOOST_PROTO_AUTO_RETURN( 135 | static_cast(e) 136 | ) 137 | }; 138 | 139 | struct MakeTest8 140 | : proto::def< proto::make( wrapper< tfx(_, _) >(_) ) > 141 | {}; 142 | 143 | void make_test8() 144 | { 145 | proto::literal i{42}; 146 | wrapper> res = MakeTest8()(i); 147 | BOOST_CHECK_EQUAL(proto::value(res.t_), 42); 148 | } 149 | } 150 | 151 | using namespace boost::unit_test; 152 | //////////////////////////////////////////////////////////////////////////////////////////////////// 153 | // init_unit_test_suite 154 | // 155 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 156 | { 157 | test_suite *test = BOOST_TEST_SUITE("test the make basic_action"); 158 | 159 | test->add(BOOST_TEST_CASE(&test_make::make_test1)); 160 | test->add(BOOST_TEST_CASE(&test_make::make_test2)); 161 | test->add(BOOST_TEST_CASE(&test_make::make_test3)); 162 | test->add(BOOST_TEST_CASE(&test_make::make_test4)); 163 | test->add(BOOST_TEST_CASE(&test_make::make_test5)); 164 | test->add(BOOST_TEST_CASE(&test_make::make_test6)); 165 | test->add(BOOST_TEST_CASE(&test_make::make_test7)); 166 | test->add(BOOST_TEST_CASE(&test_make::make_test8)); 167 | 168 | return test; 169 | } 170 | -------------------------------------------------------------------------------- /libs/proto/v5/test/matches.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // matches.cpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include "./unit_test.hpp" 11 | 12 | namespace mpl = boost::mpl; 13 | namespace proto = boost::proto; 14 | using proto::_; 15 | 16 | using int_ = proto::literal; 17 | using string_ = proto::literal; 18 | struct MyIntWrap : int_ {}; 19 | 20 | void test_matches() 21 | { 22 | static_assert(proto::matches(), ""); 23 | static_assert(proto::matches(), ""); 24 | static_assert(proto::matches(), ""); 25 | static_assert(!proto::matches(), ""); 26 | static_assert(!proto::matches(), ""); 27 | static_assert(proto::matches, proto::function(proto::terminal(int)...)>(), ""); 28 | static_assert(proto::matches, proto::function(proto::terminal(int), proto::terminal(std::string)...)>(), ""); 29 | static_assert(proto::matches, proto::function(proto::terminal(int)...)>(), ""); 30 | static_assert(!proto::matches, proto::function(proto::terminal(int)...)>(), ""); 31 | static_assert(!proto::matches(), ""); 32 | } 33 | 34 | using namespace boost::unit_test; 35 | //////////////////////////////////////////////////////////////////////////////////////////////////// 36 | // init_unit_test_suite 37 | // 38 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 39 | { 40 | test_suite *test = BOOST_TEST_SUITE("test the matches metafunction"); 41 | 42 | test->add(BOOST_TEST_CASE(&test_matches)); 43 | 44 | return test; 45 | } 46 | -------------------------------------------------------------------------------- /libs/proto/v5/test/mem_fun.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // mem_fun.hpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include 11 | #include "./unit_test.hpp" 12 | 13 | namespace mpl = boost::mpl; 14 | namespace proto = boost::proto; 15 | using proto::_; 16 | 17 | struct S 18 | { 19 | int m; 20 | 21 | void foo() 22 | {} 23 | 24 | int bar(int i) 25 | { 26 | return i; 27 | } 28 | }; 29 | 30 | void test_mem_fun() 31 | { 32 | proto::literal> plus; 33 | int i = proto::_eval()(plus(1,2)); 34 | BOOST_CHECK_EQUAL(i, 3); 35 | 36 | S s{42}; 37 | std::auto_ptr ps(new S{69}); 38 | proto::literal pm{&S::m}; 39 | proto::literal pf{&S::foo}; 40 | proto::literal pb{&S::bar}; 41 | 42 | i = proto::_eval()(pm(&s)); 43 | BOOST_CHECK_EQUAL(i, 42); 44 | 45 | i = proto::_eval()(pm(s)); 46 | BOOST_CHECK_EQUAL(i, 42); 47 | 48 | i = proto::_eval()(pm(ps)); 49 | BOOST_CHECK_EQUAL(i, 69); 50 | 51 | proto::_eval()(pf(&s)); 52 | proto::_eval()(pf(s)); 53 | proto::_eval()(pf(ps)); 54 | 55 | i = proto::_eval()(pb(&s, 1)); 56 | BOOST_CHECK_EQUAL(i, 1); 57 | 58 | i = proto::_eval()(pb(s, 2)); 59 | BOOST_CHECK_EQUAL(i, 2); 60 | 61 | i = proto::_eval()(pb(ps, 3)); 62 | BOOST_CHECK_EQUAL(i, 3); 63 | 64 | i = proto::_eval()(&s ->* pm); 65 | BOOST_CHECK_EQUAL(i, 42); 66 | 67 | i = proto::_eval()(s ->* pm); 68 | BOOST_CHECK_EQUAL(i, 42); 69 | 70 | i = proto::_eval()(ps ->* pm); 71 | BOOST_CHECK_EQUAL(i, 69); 72 | 73 | proto::_eval()((&s ->* pf)()); 74 | proto::_eval()((s ->* pf)()); 75 | proto::_eval()((ps ->* pf)()); 76 | 77 | i = proto::_eval()((&s ->* pb)(1)); 78 | BOOST_CHECK_EQUAL(i, 1); 79 | 80 | i = proto::_eval()((s ->* pb)(2)); 81 | BOOST_CHECK_EQUAL(i, 2); 82 | 83 | i = proto::_eval()((ps ->* pb)(3)); 84 | BOOST_CHECK_EQUAL(i, 3); 85 | } 86 | 87 | // other miscelaneous test cases 88 | void test_mem_fun_2() 89 | { 90 | S s{43}; 91 | S *ps = &s; 92 | int &j = proto::mem_ptr()(&s, &S::m); 93 | int &j2 = proto::mem_ptr()(ps, &S::m); 94 | BOOST_CHECK_EQUAL(j, 43); 95 | BOOST_CHECK_EQUAL(j2, 43); 96 | 97 | int k = proto::mem_ptr()(&s, &S::bar)(42); 98 | int k2 = proto::mem_ptr()(ps, &S::bar)(42); 99 | BOOST_CHECK_EQUAL(k, 42); 100 | BOOST_CHECK_EQUAL(k2, 42); 101 | 102 | proto::literal i; 103 | proto::expr & 105 | , proto::terminal(int S::*) 106 | )> x = proto::mem_ptr()(i, &S::m); 107 | 108 | int S::*pm = &S::m; 109 | proto::expr & 111 | , proto::terminal(int S::*&) 112 | )> x2 = proto::mem_ptr()(i, pm); 113 | 114 | auto x3 = proto::mem_ptr()(i, &S::foo); 115 | static_assert(proto::is_expr::value, ""); 116 | 117 | BOOST_PROTO_IGNORE_UNUSED(x, x2, x3); 118 | } 119 | 120 | using namespace boost::unit_test; 121 | //////////////////////////////////////////////////////////////////////////////////////////////////// 122 | // init_unit_test_suite 123 | // 124 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 125 | { 126 | test_suite *test = BOOST_TEST_SUITE("tests for eval with functions and member pointer ops"); 127 | 128 | test->add(BOOST_TEST_CASE(&test_mem_fun)); 129 | test->add(BOOST_TEST_CASE(&test_mem_fun_2)); 130 | 131 | return test; 132 | } 133 | -------------------------------------------------------------------------------- /libs/proto/v5/test/mpl.cpp: -------------------------------------------------------------------------------- 1 | /////////////////////////////////////////////////////////////////////////////// 2 | // mpl.hpp 3 | // 4 | // Copyright 2013 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "./unit_test.hpp" 13 | 14 | namespace mpl = boost::mpl; 15 | namespace proto = boost::proto; 16 | namespace fusion = boost::fusion; 17 | using proto::_; 18 | 19 | template 20 | struct my_expr 21 | : proto::expr> 22 | { 23 | using tag = fusion::fusion_sequence_tag; 24 | using proto::expr>::expr; 25 | }; 26 | 27 | // Test that we can call mpl algorithms on proto expression types, and get proto expression types back 28 | void test_mpl() 29 | { 30 | my_expr i; 31 | auto e = i + i; 32 | 33 | static_assert( 34 | std::is_same< 35 | mpl::pop_back::type 36 | , my_expr&)> 37 | >::value 38 | , "" 39 | ); 40 | } 41 | 42 | using namespace boost::unit_test; 43 | /////////////////////////////////////////////////////////////////////////////// 44 | // init_unit_test_suite 45 | // 46 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 47 | { 48 | test_suite *test = BOOST_TEST_SUITE("test proto mpl integration via fusion"); 49 | 50 | test->add(BOOST_TEST_CASE(&test_mpl)); 51 | 52 | return test; 53 | } 54 | -------------------------------------------------------------------------------- /libs/proto/v5/test/noinvoke.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // noinvoke.hpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include "./unit_test.hpp" 11 | namespace proto=boost::proto; 12 | using proto::_; 13 | 14 | struct Test 15 | : proto::def< 16 | proto::make( 17 | proto::noinvoke< 18 | // This remove_pointer invocation is bloked by noinvoke 19 | std::remove_pointer< 20 | // This add_pointer invocation is *not* blocked by noinvoke 21 | std::add_pointer<_> 22 | > 23 | >() 24 | ) 25 | > 26 | {}; 27 | 28 | struct Test2 29 | : proto::def< 30 | // This add_pointer gets invoked because a substitution takes place 31 | // within it. 32 | proto::make( 33 | std::add_pointer< 34 | proto::noinvoke< 35 | // This remove_pointer invocation is bloked by noinvoke 36 | std::remove_pointer< 37 | // This add_pointer invocation is *not* blocked by noinvoke 38 | std::add_pointer<_> 39 | > 40 | > 41 | >() 42 | ) 43 | > 44 | {}; 45 | 46 | template 47 | struct select2nd 48 | { 49 | using type = U; 50 | }; 51 | 52 | struct Test3 53 | : proto::def< 54 | // This add_pointer gets invoked because a substitution takes place 55 | // within it. 56 | proto::make( 57 | select2nd< 58 | void 59 | , proto::noinvoke< 60 | // This remove_pointer invocation is bloked by noinvoke 61 | select2nd< 62 | void 63 | // This add_pointer invocation is *not* blocked by noinvoke 64 | , std::add_pointer<_> 65 | > 66 | > 67 | >() 68 | ) 69 | > 70 | {}; 71 | 72 | void test_noinvoke() 73 | { 74 | using Int = proto::literal; 75 | Int i {42}; 76 | 77 | static_assert( 78 | std::is_same< 79 | std::result_of::type 80 | , std::remove_pointer 81 | >::value 82 | , "test 1" 83 | ); 84 | 85 | std::remove_pointer t = Test()(i); 86 | BOOST_PROTO_IGNORE_UNUSED(t); 87 | 88 | static_assert( 89 | std::is_same< 90 | std::result_of::type 91 | , std::remove_pointer * 92 | >::value 93 | , "test 2" 94 | ); 95 | 96 | std::remove_pointer * t2 = Test2()(i); 97 | BOOST_PROTO_IGNORE_UNUSED(t2); 98 | 99 | static_assert( 100 | std::is_same< 101 | std::result_of::type 102 | , select2nd 103 | >::value 104 | , "test 3" 105 | ); 106 | 107 | select2nd t3 = Test3()(i); 108 | BOOST_PROTO_IGNORE_UNUSED(t3); 109 | } 110 | 111 | using namespace boost::unit_test; 112 | //////////////////////////////////////////////////////////////////////////////////////////////////// 113 | // init_unit_test_suite 114 | // 115 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 116 | { 117 | test_suite *test = BOOST_TEST_SUITE("test proto::noinvoke"); 118 | 119 | test->add(BOOST_TEST_CASE(&test_noinvoke)); 120 | 121 | return test; 122 | } 123 | -------------------------------------------------------------------------------- /libs/proto/v5/test/pack_expansion.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // pack_expansion.hpp 3 | // 4 | // Copyright 2008 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include 11 | #include "./unit_test.hpp" 12 | 13 | namespace mpl = boost::mpl; 14 | namespace proto = boost::proto; 15 | using proto::_; 16 | 17 | struct do_eval 18 | { 19 | template 20 | auto operator()(proto::plus, Left left, Right right) const 21 | BOOST_PROTO_AUTO_RETURN( 22 | left + right 23 | ) 24 | 25 | template 26 | auto operator()(proto::multiplies, Left left, Right right) const 27 | BOOST_PROTO_AUTO_RETURN( 28 | left * right 29 | ) 30 | }; 31 | 32 | struct eval 33 | : proto::def< 34 | proto::match( 35 | proto::case_(proto::terminal(_), 36 | proto::_value 37 | ) 38 | , proto::default_( 39 | // could use _tag_of here, but make is a nice test case. 40 | do_eval(proto::make(proto::result_of::tag_of<_>()), eval(proto::pack(_))...) 41 | ) 42 | ) 43 | > 44 | {}; 45 | 46 | void test_call_pack() 47 | { 48 | proto::literal i {42}; 49 | int res = eval()(i); 50 | BOOST_CHECK_EQUAL(res, 42); 51 | res = eval()(i + 2); 52 | BOOST_CHECK_EQUAL(res, 44); 53 | res = eval()(i * 2); 54 | BOOST_CHECK_EQUAL(res, 84); 55 | res = eval()(i * 2 + 4); 56 | BOOST_CHECK_EQUAL(res, 88); 57 | } 58 | 59 | struct make_pair 60 | : proto::def(proto::_value(proto::pack(_))...))> 61 | {}; 62 | 63 | void test_make_pack() 64 | { 65 | proto::literal i {42}; 66 | std::pair p = make_pair()(i + 43); 67 | BOOST_CHECK_EQUAL(p.first, 42); 68 | BOOST_CHECK_EQUAL(p.second, 43); 69 | } 70 | 71 | struct do_accept_pairs 72 | { 73 | void disp(std::ostream &) const {} 74 | 75 | template 76 | void disp(std::ostream & sout, Head h, Tail ...t) const 77 | { 78 | sout << '(' << h.first << ',' << h.second << ')'; 79 | disp(sout, t...); 80 | } 81 | 82 | template 83 | void operator()(std::ostream & sout, std::pair... pairs) const 84 | { 85 | disp(sout, pairs...); 86 | } 87 | }; 88 | 89 | struct front 90 | { 91 | template 92 | Head && operator()(Head && h, Tail &&...) const 93 | { 94 | return static_cast(h); 95 | } 96 | }; 97 | 98 | // Test expanding multiple packs in parallel 99 | struct accept_pairs 100 | : proto::def< 101 | do_accept_pairs( 102 | proto::_data 103 | , proto::functional::std::make_pair( 104 | proto::_value(proto::pack(proto::_child<0>)) 105 | , proto::_value(proto::pack(proto::_child<1>)) 106 | )... 107 | ) 108 | > 109 | {}; 110 | 111 | // Test expanding multiple packs in parallel *and* a nested pack expansion. 112 | struct accept_pairs_2 113 | : proto::def< 114 | do_accept_pairs( 115 | proto::_data 116 | , proto::functional::std::make_pair( 117 | proto::_value(proto::pack(front(proto::pack(_)...))) 118 | , proto::_value(proto::pack(proto::_child<1>)) 119 | )... 120 | ) 121 | > 122 | {}; 123 | 124 | void test_multiple_packs() 125 | { 126 | proto::literal i{42}; 127 | std::ostringstream sout; 128 | accept_pairs()( i(1,2) + i("hello","world"), proto::data = sout); 129 | BOOST_CHECK_EQUAL( sout.str(), std::string("(42,42)(1,hello)(2,world)") ); 130 | 131 | sout.str(""); 132 | accept_pairs_2()(i(1,2) + i("this","that"), proto::data = sout); 133 | BOOST_CHECK_EQUAL( sout.str(), std::string("(42,42)(1,this)(2,that)") ); 134 | } 135 | 136 | using namespace boost::unit_test; 137 | //////////////////////////////////////////////////////////////////////////////////////////////////// 138 | // init_unit_test_suite 139 | // 140 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 141 | { 142 | test_suite *test = BOOST_TEST_SUITE("test for proto::pack, pack expansion, and unpack patterns"); 143 | 144 | test->add(BOOST_TEST_CASE(&test_call_pack)); 145 | test->add(BOOST_TEST_CASE(&test_make_pack)); 146 | test->add(BOOST_TEST_CASE(&test_multiple_packs)); 147 | 148 | return test; 149 | } 150 | -------------------------------------------------------------------------------- /libs/proto/v5/test/passthru.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // passthru.hpp 3 | // 4 | // Copyright 2013 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include "./unit_test.hpp" 11 | namespace proto=boost::proto; 12 | using proto::_; 13 | 14 | struct MinusToPlus 15 | : proto::def< 16 | proto::match( 17 | proto::case_( 18 | proto::minus(MinusToPlus, MinusToPlus) 19 | , proto::plus(MinusToPlus(proto::_left), MinusToPlus(proto::_right)) 20 | ) 21 | , proto::case_( 22 | _(MinusToPlus...) 23 | , proto::passthru 24 | ) 25 | , proto::case_( 26 | proto::terminal(_) 27 | , proto::passthru 28 | ) 29 | ) 30 | > 31 | {}; 32 | 33 | void test_passthru() 34 | { 35 | using namespace proto::literals; 36 | auto x = - (1_et - 2); 37 | proto::expr< 38 | proto::negate( 39 | proto::plus( 40 | proto::terminal(unsigned long long) 41 | , proto::terminal(int) 42 | ) 43 | ) 44 | > y = MinusToPlus()(x); 45 | BOOST_PROTO_IGNORE_UNUSED(y); 46 | } 47 | 48 | using namespace boost::unit_test; 49 | //////////////////////////////////////////////////////////////////////////////////////////////////// 50 | // init_unit_test_suite 51 | // 52 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 53 | { 54 | test_suite *test = BOOST_TEST_SUITE("test proto::passthru"); 55 | 56 | test->add(BOOST_TEST_CASE(&test_passthru)); 57 | 58 | return test; 59 | } 60 | -------------------------------------------------------------------------------- /libs/proto/v5/test/protect.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // protect.hpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include "./unit_test.hpp" 11 | namespace proto=boost::proto; 12 | using proto::_; 13 | 14 | template 15 | struct S 16 | {}; 17 | 18 | template 19 | struct identity 20 | { 21 | using type = T; 22 | }; 23 | 24 | struct Test 25 | : proto::def()> 26 | {}; 27 | 28 | struct Test0 29 | : proto::def())> 30 | {}; 31 | 32 | struct Test1 33 | : proto::def>())> 34 | {}; 35 | 36 | struct Test2 37 | : proto::def>())> 38 | {}; 39 | 40 | struct Test3 41 | : proto::def()>>())> 42 | {}; 43 | 44 | struct Test4 45 | : proto::def()>>())> 46 | {}; 47 | 48 | struct Test5 49 | : proto::def>()>>())> 50 | {}; 51 | 52 | void test_protect() 53 | { 54 | proto::literal i {42}; 55 | 56 | proto::literal & t = Test()(i); 57 | proto::_protect<_> t0 = Test0()(i); 58 | identity> t1 = Test1()(i); 59 | S> t2 = Test2()(i); 60 | identity()>> t3 = Test3()(i); 61 | S()>> t4 = Test4()(i); 62 | identity>()>> t5 = Test5()(i); 63 | 64 | BOOST_PROTO_IGNORE_UNUSED(t, t0, t1, t2, t3, t4, t5); 65 | } 66 | 67 | using namespace boost::unit_test; 68 | //////////////////////////////////////////////////////////////////////////////////////////////////// 69 | // init_unit_test_suite 70 | // 71 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 72 | { 73 | test_suite *test = BOOST_TEST_SUITE("test proto::_protect"); 74 | 75 | test->add(BOOST_TEST_CASE(&test_protect)); 76 | 77 | return test; 78 | } 79 | -------------------------------------------------------------------------------- /libs/proto/v5/test/unit_test.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // unit_test.hpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #ifndef BOOST_PROTO_CXX11_TEST_UNIT_TEST_HPP_INCLUDED 9 | #define BOOST_PROTO_CXX11_TEST_UNIT_TEST_HPP_INCLUDED 10 | 11 | #include 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /libs/proto/v5/test/virtual_member.cpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////////////////////////// 2 | // virtual_member.hpp 3 | // 4 | // Copyright 2012 Eric Niebler. Distributed under the Boost 5 | // Software License, Version 1.0. (See accompanying file 6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "./unit_test.hpp" 13 | 14 | namespace proto = boost::proto; 15 | using proto::_; 16 | 17 | struct foo_tag {}; 18 | struct bar_tag {}; 19 | 20 | template 21 | struct MyExpr 22 | : proto::basic_expr> 23 | { 24 | using proto::basic_expr>::basic_expr; 25 | 26 | BOOST_PROTO_EXTENDS_MEMBERS( 27 | MyExpr, 28 | ((foo_tag, foo)) 29 | ((bar_tag, bar)) 30 | ); 31 | }; 32 | 33 | using My = proto::custom>; 34 | 35 | void test_virtual_members() 36 | { 37 | My::terminal xxx{42}; 38 | My::terminal & r = proto::child<0>(xxx.foo); 39 | proto::literal & e = proto::child<1>(xxx.foo); 40 | 41 | static_assert(std::is_lvalue_reference(xxx.foo))>::value, ""); 42 | static_assert(std::is_rvalue_reference(My::terminal().foo))>::value, ""); 43 | 44 | static_assert(std::is_lvalue_reference(xxx.foo))>::value, ""); 45 | static_assert(std::is_rvalue_reference(My::terminal().foo))>::value, ""); 46 | 47 | BOOST_CHECK_EQUAL(42, proto::value(xxx)); 48 | BOOST_CHECK_EQUAL(42, proto::value(r)); 49 | 50 | // These addresses had better be the same 51 | BOOST_CHECK_EQUAL(boost::addressof(xxx), boost::addressof(r)); 52 | BOOST_CHECK_EQUAL(boost::addressof(proto::exprs::access::proto_args(xxx.foo).proto_child1), boost::addressof(e)); 53 | 54 | // Check that member expressions match their grammars 55 | struct G 56 | : proto::def< 57 | proto::match( 58 | proto::case_( 59 | proto::member(proto::terminal(int), proto::terminal(foo_tag)) 60 | , proto::passthru 61 | ) 62 | ) 63 | > 64 | {}; 65 | 66 | proto::assert_matches(xxx.foo); 67 | 68 | // Check that the pass-through basic_action handles virtual members correctly. 69 | My::member, proto::literal> tx = G()(xxx.foo); 70 | BOOST_PROTO_IGNORE_UNUSED(tx); 71 | } 72 | 73 | using namespace boost::unit_test; 74 | //////////////////////////////////////////////////////////////////////////////////////////////////// 75 | // init_unit_test_suite 76 | // 77 | test_suite* init_unit_test_suite( int argc, char* argv[] ) 78 | { 79 | test_suite *test = BOOST_TEST_SUITE("tests for virtual members"); 80 | 81 | test->add(BOOST_TEST_CASE(&test_virtual_members)); 82 | 83 | return test; 84 | } 85 | --------------------------------------------------------------------------------