diff --git a/.travis.yml b/.travis.yml index cb880f7..c6c8d83 100644 --- a/.travis.yml +++ b/.travis.yml @@ -168,14 +168,14 @@ script: - if [ ! -d build ]; then mkdir build; fi - cd build - if [[ "$CXX11" == "on" ]]; then export CXXFLAGS="${CXXFLAGS} -std=c++11"; fi - - if [[ "$HAS_GENERIC_LAMBDA" == "on" ]]; then export CXXFLAGS="${CXXFLAGS} -DFIT_HAS_GENERIC_LAMBDA=1"; fi + - if [[ "$HAS_GENERIC_LAMBDA" == "on" ]]; then export CXXFLAGS="${CXXFLAGS} -DBOOST_FIT_HAS_GENERIC_LAMBDA=1"; fi - if [[ "$ASAN" == "on" ]]; then export CXXFLAGS="${CXXFLAGS} -fsanitize=address,undefined,integer -fno-omit-frame-pointer -fno-sanitize=unsigned-integer-overflow"; fi - cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX_PATH .. - CTEST_OUTPUT_ON_FAILURE=1 CTEST_PARALLEL_LEVEL=2 make -j2 check VERBOSE=1 - make install - pkg-config fit --cflags - cd ../include - - HEADERS=$(echo fit/*.hpp) + - HEADERS=$(echo boost/fit/*.hpp) - for file in $HEADERS; do echo -e "#include <$file>\nint main() {}" | $CXX -std=gnu++0x `pkg-config fit --cflags` -x c++ -S -; done - cd .. - rm -rf build/ diff --git a/CMakeLists.txt b/CMakeLists.txt index e5e73f4..299d995 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,7 +33,7 @@ foreach(flag ${ENABLE_CXXFLAGS_TO_CHECK}) endif() endforeach() -install (DIRECTORY include/fit DESTINATION include) +install (DIRECTORY include/boost DESTINATION include) configure_file(fit.pc.in fit.pc) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/fit.pc DESTINATION lib/pkgconfig) diff --git a/README.md b/README.md index 6b5949c..844e501 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ Fit is divided into three components: * Functions: These return functions that achieve a specific purpose. * Utilities: These are general utilities that are useful when defining or using functions -Github: [http://github.com/pfultz2/Fit](http://github.com/pfultz2/Fit) +Github: [https://github.com/pfultz2/Fit/tree/boost](https://github.com/pfultz2/Fit/tree/boost) -Documentation: [http://fit.readthedocs.org](http://fit.readthedocs.org) +Documentation: [http://pfultz2.github.io/Fit/doc/html/](http://pfultz2.github.io/Fit/doc/html/) Quick Start =========== @@ -36,28 +36,28 @@ In C++, a function object is just a class that overrides the call operator like } }; -There are few things to note about this. First, the call operator member function is always declared `const`, which is generally required to be used with Fit.(Note: The [`mutable_`](http://fit.readthedocs.org/en/latest/mutable/index.html) adaptor can be used to make a mutable function object have a `const` call operator, but this should generally be avoided). Secondly, the `sum_f` class must be constructed first before it can be called: +There are few things to note about this. First, the call operator member function is always declared `const`, which is generally required to be used with Fit.(Note: The [`mutable_`](http://pfultz2.github.io/Fit/doc/html//en/latest/mutable/index.html) adaptor can be used to make a mutable function object have a `const` call operator, but this should generally be avoided). Secondly, the `sum_f` class must be constructed first before it can be called: auto three = sum_f()(1, 2); -We can make it behave like a regular function if we construct the class as a global variable. The Fit library provides [`FIT_STATIC_FUNCTION`](http://fit.readthedocs.org/en/latest/function/index.html) to properly initialize the the function object at compile-time to avoid the [static initialization order fiasco](https://isocpp.org/wiki/faq/ctors#static-init-order) and possible ODR violations: +We can make it behave like a regular function if we construct the class as a global variable. The Fit library provides [`BOOST_FIT_STATIC_FUNCTION`](http://pfultz2.github.io/Fit/doc/html//en/latest/function/index.html) to properly initialize the the function object at compile-time to avoid the [static initialization order fiasco](https://isocpp.org/wiki/faq/ctors#static-init-order) and possible ODR violations: - FIT_STATIC_FUNCTION(sum) = sum_f(); + BOOST_FIT_STATIC_FUNCTION(sum) = sum_f(); Adaptors -------- -Now we have defined the function as a function object, we can add new "enhancements" to the function. We could make the function pipable using the [`pipable`](http://fit.readthedocs.org/en/latest/pipable/index.html) adaptor: +Now we have defined the function as a function object, we can add new "enhancements" to the function. We could make the function pipable using the [`pipable`](http://pfultz2.github.io/Fit/doc/html//en/latest/pipable/index.html) adaptor: - FIT_STATIC_FUNCTION(sum) = pipable_adaptor(); + BOOST_FIT_STATIC_FUNCTION(sum) = pipable_adaptor(); This allows the parameters to piped into it, like this: auto three = 1 | sum(2); -Or we could make it an infix named operator as well using the [`infix`](http://fit.readthedocs.org/en/latest/infix/index.html) adaptor: +Or we could make it an infix named operator as well using the [`infix`](http://pfultz2.github.io/Fit/doc/html//en/latest/infix/index.html) adaptor: - FIT_STATIC_FUNCTION(sum) = infix_adaptor(); + BOOST_FIT_STATIC_FUNCTION(sum) = infix_adaptor(); And it could be called like this: @@ -72,9 +72,9 @@ Additionally each of the adaptors have a corresponding function version without Lambdas ------- -Instead of writing function objects which can be a little verbose, we can write the functions as lambdas instead. However, by default lambdas cannot be statically initialized at compile time. So we can use the [`FIT_STATIC_LAMBDA`](http://fit.readthedocs.org/en/latest/lambda/index.html) to initialize them at compile time: +Instead of writing function objects which can be a little verbose, we can write the functions as lambdas instead. However, by default lambdas cannot be statically initialized at compile time. So we can use the [`BOOST_FIT_STATIC_LAMBDA`](http://pfultz2.github.io/Fit/doc/html//en/latest/lambda/index.html) to initialize them at compile time: - FIT_STATIC_FUNCTION(sum) = FIT_STATIC_LAMBDA(auto x, auto y) + BOOST_FIT_STATIC_FUNCTION(sum) = BOOST_FIT_STATIC_LAMBDA(auto x, auto y) { return x + y; }; @@ -82,15 +82,15 @@ Instead of writing function objects which can be a little verbose, we can write And we can apply the same adaptors as well: // Pipable sum - FIT_STATIC_FUNCTION(sum) = pipable(FIT_STATIC_LAMBDA(auto x, auto y) + BOOST_FIT_STATIC_FUNCTION(sum) = pipable(BOOST_FIT_STATIC_LAMBDA(auto x, auto y) { return x + y; }); -We can also use [`FIT_STATIC_LAMBDA_FUNCTION`](http://fit.readthedocs.org/en/latest/lambda.md) so we dont have to repeat [`FIT_STATIC_LAMBDA`](lambda/index.html) for adaptors, and it can help avoid possible ODR violations as well: +We can also use [`BOOST_FIT_STATIC_LAMBDA_FUNCTION`](http://pfultz2.github.io/Fit/doc/html//en/latest/lambda.md) so we dont have to repeat [`BOOST_FIT_STATIC_LAMBDA`](lambda/index.html) for adaptors, and it can help avoid possible ODR violations as well: // Pipable sum - FIT_STATIC_LAMBDA_FUNCTION(sum) = pipable([](auto x, auto y) + BOOST_FIT_STATIC_LAMBDA_FUNCTION(sum) = pipable([](auto x, auto y) { return x + y; }); @@ -100,9 +100,9 @@ As we will see, this can help make it cleaner when we are defining several lambd Overloading ----------- -Now, Fit provides two ways of doing overloading. The [`match`](http://fit.readthedocs.org/en/latest/match/index.html) adaptor will call a function based on C++ overload resolution, which tries to find the best match, like this: +Now, Fit provides two ways of doing overloading. The [`match`](http://pfultz2.github.io/Fit/doc/html//en/latest/match/index.html) adaptor will call a function based on C++ overload resolution, which tries to find the best match, like this: - FIT_STATIC_LAMBDA_FUNCTION(print) = match( + BOOST_FIT_STATIC_LAMBDA_FUNCTION(print) = match( [](int x) { std::cout << "Integer: " << x << std::endl; @@ -113,10 +113,10 @@ Now, Fit provides two ways of doing overloading. The [`match`](http://fit.readth } ); -However, when trying to do overloading involving something more generic, it can lead to ambiguities. So the [`conditional`](http://fit.readthedocs.org/en/latest/conditional/index.html) adaptor will pick the first function that is callable. This allows ordering the functions based on which one is more important. Say we would like to write a `print` function that can print not only using `cout` but can also print the values in ranges. We could write something like this: +However, when trying to do overloading involving something more generic, it can lead to ambiguities. So the [`conditional`](http://pfultz2.github.io/Fit/doc/html//en/latest/conditional/index.html) adaptor will pick the first function that is callable. This allows ordering the functions based on which one is more important. Say we would like to write a `print` function that can print not only using `cout` but can also print the values in ranges. We could write something like this: - FIT_STATIC_LAMBDA_FUNCTION(print) = conditional( + BOOST_FIT_STATIC_LAMBDA_FUNCTION(print) = conditional( [](const auto& x) -> decltype(std::cout << x, void()) { std::cout << x << std::endl; @@ -134,10 +134,10 @@ So the `-> decltype(std::cout << x, void())` will only make the function callabl using std::begin; template - auto adl_begin(R&& r) -> FIT_RETURNS(begin(r)); + auto adl_begin(R&& r) -> BOOST_FIT_RETURNS(begin(r)); } - FIT_STATIC_LAMBDA_FUNCTION(print) = conditional( + BOOST_FIT_STATIC_LAMBDA_FUNCTION(print) = conditional( [](const auto& x) -> decltype(std::cout << x, void()) { std::cout << x << std::endl; @@ -151,16 +151,16 @@ So the `-> decltype(std::cout << x, void())` will only make the function callabl Tuples ------ -We could extend this to printing tuples as well. We will need to combine a couple of functions to make a `for_each_tuple`, which let us call a function for each element. First, the [`by`](http://fit.readthedocs.org/en/latest/by.md) adaptor will let us apply a function to each argument passed in, and the [`unpack`](unpack/index.html) adaptor will unpack the elements to a tuple and apply them to the argument: +We could extend this to printing tuples as well. We will need to combine a couple of functions to make a `for_each_tuple`, which let us call a function for each element. First, the [`by`](http://pfultz2.github.io/Fit/doc/html//en/latest/by.md) adaptor will let us apply a function to each argument passed in, and the [`unpack`](unpack/index.html) adaptor will unpack the elements to a tuple and apply them to the argument: - FIT_STATIC_LAMBDA_FUNCTION(for_each_tuple) = [](const auto& sequence, auto f) + BOOST_FIT_STATIC_LAMBDA_FUNCTION(for_each_tuple) = [](const auto& sequence, auto f) { return unpack(by(f))(sequence) }; So now we can add an overload for tuples: - FIT_STATIC_LAMBDA_FUNCTION(print) = conditional( + BOOST_FIT_STATIC_LAMBDA_FUNCTION(print) = conditional( [](const auto& x) -> decltype(std::cout << x, void()) { std::cout << x << std::endl; @@ -178,14 +178,14 @@ So now we can add an overload for tuples: } ); -Since we can't use a lambda inside of `decltype` we just put [`identity`](http://fit.readthedocs.org/en/latest/identity/index.html) instead. +Since we can't use a lambda inside of `decltype` we just put [`identity`](http://pfultz2.github.io/Fit/doc/html//en/latest/identity/index.html) instead. Recursive --------- -Even though we are using lambdas, we can easily make this recursive using the [`fix`](http://fit.readthedocs.org/en/latest/fix/index.html) adaptor. This implements a fix point combinator, which passes the function(ie itself) in as the first argument, so we could write this: +Even though we are using lambdas, we can easily make this recursive using the [`fix`](http://pfultz2.github.io/Fit/doc/html//en/latest/fix/index.html) adaptor. This implements a fix point combinator, which passes the function(ie itself) in as the first argument, so we could write this: - FIT_STATIC_LAMBDA_FUNCTION(print) = fix(conditional( + BOOST_FIT_STATIC_LAMBDA_FUNCTION(print) = fix(conditional( [](auto, const auto& x) -> decltype(std::cout << x, void()) { std::cout << x << std::endl; @@ -205,7 +205,7 @@ Variadic We can also make this `print` function varidiac, so it prints every argument passed into it. We just rename our original `print` function to `simple_print`: - FIT_STATIC_LAMBDA_FUNCTION(simple_print) = fix(conditional( + BOOST_FIT_STATIC_LAMBDA_FUNCTION(simple_print) = fix(conditional( [](auto, const auto& x) -> decltype(std::cout << x, void()) { std::cout << x << std::endl; @@ -220,9 +220,9 @@ We can also make this `print` function varidiac, so it prints every argument pas } )); -And then apply the [`by`](http://fit.readthedocs.org/en/latest/by/index.html) adaptor to `simple_print`: +And then apply the [`by`](http://pfultz2.github.io/Fit/doc/html//en/latest/by/index.html) adaptor to `simple_print`: - FIT_STATIC_LAMBDA_FUNCTION(print) = by(simple_print); + BOOST_FIT_STATIC_LAMBDA_FUNCTION(print) = by(simple_print); Requirements ============ diff --git a/appveyor.yml b/appveyor.yml index 6d8ef9d..add5948 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -28,7 +28,7 @@ build_script: - cmd: python setup.py - cmd: mkdir build - cmd: cd build - - cmd: SET CXXFLAGS=/DFIT_HAS_GENERIC_LAMBDA=1 + - cmd: SET CXXFLAGS=/DBOOST_FIT_HAS_GENERIC_LAMBDA=1 - cmd: cmake .. -G"%GENERATOR%" - cmd: cmake --build . --config %CONFIG% --target check diff --git a/doc/genreadme b/doc/genreadme index b2f0c4c..ba86e13 100755 --- a/doc/genreadme +++ b/doc/genreadme @@ -1,3 +1,3 @@ #!/bin/bash -cat src/index.md src/quickstart.md src/requirements.md | sed -e 's,\](\(.*\)\.md),](http://fit.readthedocs.org/en/latest/\1/index.html\),g' +cat src/index.md src/quickstart.md src/requirements.md | sed -e 's,\](\(.*\)\.md),](http://pfultz2.github.io/Fit/doc/html//en/latest/\1/index.html\),g' diff --git a/doc/src/configurations.md b/doc/src/configurations.md index 48d70c6..9ace1da 100644 --- a/doc/src/configurations.md +++ b/doc/src/configurations.md @@ -6,6 +6,6 @@ There are several configuration that control the behavior in the Fit library. | Name | Description | |-------------------------------|--------------------------------------------------------------------------------| -| FIT_CHECK_UNPACK_SEQUENCE | Unpack has extra checks to ensure that the function will be invoked with the sequence. This extra check can help improve error reporting but it can slow down compilation. This is enabled by default. | -| FIT_NO_EXPRESSION_SFINAE | This controls whether the Fit library will use expression SFINAE to detect the callability of functions. On MSVC, this is enabled by default, since it does not have full support for expression SFINAE. | -| FIT_RECURSIVE_CONSTEXPR_DEPTH | Because C++ instantiates `constexpr` functions eagerly, recursion with `constexpr` functions can cause the compiler to reach its internal limits. The setting is used by Fit to set a limit on recursion depth to avoid infinite template instantiations. The default is 16, but increasing the limit can increase compile times. | +| BOOST_FIT_CHECK_UNPACK_SEQUENCE | Unpack has extra checks to ensure that the function will be invoked with the sequence. This extra check can help improve error reporting but it can slow down compilation. This is enabled by default. | +| BOOST_FIT_NO_EXPRESSION_SFINAE | This controls whether the Fit library will use expression SFINAE to detect the callability of functions. On MSVC, this is enabled by default, since it does not have full support for expression SFINAE. | +| BOOST_FIT_RECURSIVE_CONSTEXPR_DEPTH | Because C++ instantiates `constexpr` functions eagerly, recursion with `constexpr` functions can cause the compiler to reach its internal limits. The setting is used by Fit to set a limit on recursion depth to avoid infinite template instantiations. The default is 16, but increasing the limit can increase compile times. | diff --git a/doc/src/faq.md b/doc/src/faq.md index 30b9c36..880f5e4 100644 --- a/doc/src/faq.md +++ b/doc/src/faq.md @@ -1,7 +1,7 @@ FAQ === -#### Q: Is the reinterpret cast in FIT_STATIC_LAMBDA undefined behaviour? +#### Q: Is the reinterpret cast in BOOST_FIT_STATIC_LAMBDA undefined behaviour? Not really, since the objects are empty, there is no data access. I have a static assert to guard against this restriction. diff --git a/doc/src/index.md b/doc/src/index.md index 1700cf5..df185be 100644 --- a/doc/src/index.md +++ b/doc/src/index.md @@ -15,6 +15,6 @@ Fit is divided into three components: * Functions: These return functions that achieve a specific purpose. * Utilities: These are general utilities that are useful when defining or using functions -Github: [http://github.com/pfultz2/Fit](http://github.com/pfultz2/Fit) +Github: [https://github.com/pfultz2/Fit/tree/boost](https://github.com/pfultz2/Fit/tree/boost) -Documentation: [http://fit.readthedocs.org](http://fit.readthedocs.org) +Documentation: [http://pfultz2.github.io/Fit/doc/html/](http://pfultz2.github.io/Fit/doc/html/) diff --git a/doc/src/more_examples.md b/doc/src/more_examples.md index 09884d3..35a2cd4 100644 --- a/doc/src/more_examples.md +++ b/doc/src/more_examples.md @@ -10,12 +10,12 @@ metaprogramming. Lets take look at some of the use cases for using the Fit libra Initialization -------------- -The [`FIT_STATIC_FUNCTION`](function.md) will help initialize function objects at +The [`BOOST_FIT_STATIC_FUNCTION`](function.md) will help initialize function objects at global scope, and will ensure that it is initialized at compile-time and (on platforms that support it) will have a unique address across translation units, thereby reducing executable bloat and potential ODR violations. -In addition, [`FIT_STATIC_LAMBDA_FUNCTION`](lambda.md) allows initializing a lambda +In addition, [`BOOST_FIT_STATIC_LAMBDA_FUNCTION`](lambda.md) allows initializing a lambda in the same manner. This allows for simple and compact function definitions when working with generic lambdas and function adaptors. @@ -34,12 +34,12 @@ answers usually involve some amount of metaprogramming using either `void_t` or `is_detected`(see [n4502](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4502.pdf)). However, with the Fit library it can simply be written like this: - FIT_STATIC_LAMBDA_FUNCTION(stringify) = conditional( - [](auto x) FIT_RETURNS(to_string(x)), - [](auto x) FIT_RETURNS(static_cast(ostringstream() << x).str()) + BOOST_FIT_STATIC_LAMBDA_FUNCTION(stringify) = conditional( + [](auto x) BOOST_FIT_RETURNS(to_string(x)), + [](auto x) BOOST_FIT_RETURNS(static_cast(ostringstream() << x).str()) ); -In addition, this can be used with the [`fit::if_`](if.md) decorator to create `static_if`-like +In addition, this can be used with the [`boost::fit::if_`](if.md) decorator to create `static_if`-like constructs. For example, Baptiste Wicht discusses how one could write `static_if` in C++ [here](http://baptiste-wicht.com/posts/2015/07/simulate-static_if-with-c11c14.html). He wants to be able to write this: @@ -102,8 +102,8 @@ this: std::true_type{} ); - FIT_STATIC_LAMBDA_FUNCTION(has_pointer_operators) = conditional( - FIT_LIFT(has_pointer_member), + BOOST_FIT_STATIC_LAMBDA_FUNCTION(has_pointer_operators) = conditional( + BOOST_FIT_LIFT(has_pointer_member), [](auto* x) -> bool_constant<(!std::is_void())> { return {}; }, always(std::false_type{}) ); @@ -147,13 +147,13 @@ Varidiac parameters As shown in the [quick start guide](quickstart.md) the [`by`](by.md) adaptor can be used to apply a function to each argument, so we could write a simple varidiac print function like this: - FIT_STATIC_FUNCTION(print) = by(std::cout << _); + BOOST_FIT_STATIC_FUNCTION(print) = by(std::cout << _); We can also take binary functions and turn them easily into varidiac functions as well using [`compress`](compress.md). So a varidiac `max` function could be written like this: - FIT_STATIC_FUNCTION(max) = compress(FIT_LIFT(std::max)); + BOOST_FIT_STATIC_FUNCTION(max) = compress(BOOST_FIT_LIFT(std::max)); Polymorphic constructors ------------------------ @@ -162,7 +162,7 @@ Writing polymorphic constructors(such as `make_tuple`) is a boilerplate that has to be written over and over again for template classes. With [`construct`](construct.md) this is easier. For example, `make_tuple` can be written simply as this: - FIT_STATIC_FUNCTION(make_tuple) = construct().by(decay()); + BOOST_FIT_STATIC_FUNCTION(make_tuple) = construct().by(decay()); Extension methods ----------------- diff --git a/doc/src/quickstart.md b/doc/src/quickstart.md index 3a0e632..c21cb3d 100644 --- a/doc/src/quickstart.md +++ b/doc/src/quickstart.md @@ -20,16 +20,16 @@ There are few things to note about this. First, the call operator member functio auto three = sum_f()(1, 2); -We can make it behave like a regular function if we construct the class as a global variable. The Fit library provides [`FIT_STATIC_FUNCTION`](function.md) to properly initialize the the function object at compile-time to avoid the [static initialization order fiasco](https://isocpp.org/wiki/faq/ctors#static-init-order) and possible ODR violations: +We can make it behave like a regular function if we construct the class as a global variable. The Fit library provides [`BOOST_FIT_STATIC_FUNCTION`](function.md) to properly initialize the the function object at compile-time to avoid the [static initialization order fiasco](https://isocpp.org/wiki/faq/ctors#static-init-order) and possible ODR violations: - FIT_STATIC_FUNCTION(sum) = sum_f(); + BOOST_FIT_STATIC_FUNCTION(sum) = sum_f(); Adaptors -------- Now we have defined the function as a function object, we can add new "enhancements" to the function. We could make the function pipable using the [`pipable`](pipable.md) adaptor: - FIT_STATIC_FUNCTION(sum) = pipable_adaptor(); + BOOST_FIT_STATIC_FUNCTION(sum) = pipable_adaptor(); This allows the parameters to piped into it, like this: @@ -37,7 +37,7 @@ This allows the parameters to piped into it, like this: Or we could make it an infix named operator as well using the [`infix`](infix.md) adaptor: - FIT_STATIC_FUNCTION(sum) = infix_adaptor(); + BOOST_FIT_STATIC_FUNCTION(sum) = infix_adaptor(); And it could be called like this: @@ -52,9 +52,9 @@ Additionally each of the adaptors have a corresponding function version without Lambdas ------- -Instead of writing function objects which can be a little verbose, we can write the functions as lambdas instead. However, by default lambdas cannot be statically initialized at compile time. So we can use the [`FIT_STATIC_LAMBDA`](lambda.md) to initialize them at compile time: +Instead of writing function objects which can be a little verbose, we can write the functions as lambdas instead. However, by default lambdas cannot be statically initialized at compile time. So we can use the [`BOOST_FIT_STATIC_LAMBDA`](lambda.md) to initialize them at compile time: - FIT_STATIC_FUNCTION(sum) = FIT_STATIC_LAMBDA(auto x, auto y) + BOOST_FIT_STATIC_FUNCTION(sum) = BOOST_FIT_STATIC_LAMBDA(auto x, auto y) { return x + y; }; @@ -62,15 +62,15 @@ Instead of writing function objects which can be a little verbose, we can write And we can apply the same adaptors as well: // Pipable sum - FIT_STATIC_FUNCTION(sum) = pipable(FIT_STATIC_LAMBDA(auto x, auto y) + BOOST_FIT_STATIC_FUNCTION(sum) = pipable(BOOST_FIT_STATIC_LAMBDA(auto x, auto y) { return x + y; }); -We can also use [`FIT_STATIC_LAMBDA_FUNCTION`](lambda.md) so we dont have to repeat [`FIT_STATIC_LAMBDA`](lambda.md) for adaptors, and it can help avoid possible ODR violations as well: +We can also use [`BOOST_FIT_STATIC_LAMBDA_FUNCTION`](lambda.md) so we dont have to repeat [`BOOST_FIT_STATIC_LAMBDA`](lambda.md) for adaptors, and it can help avoid possible ODR violations as well: // Pipable sum - FIT_STATIC_LAMBDA_FUNCTION(sum) = pipable([](auto x, auto y) + BOOST_FIT_STATIC_LAMBDA_FUNCTION(sum) = pipable([](auto x, auto y) { return x + y; }); @@ -82,7 +82,7 @@ Overloading Now, Fit provides two ways of doing overloading. The [`match`](match.md) adaptor will call a function based on C++ overload resolution, which tries to find the best match, like this: - FIT_STATIC_LAMBDA_FUNCTION(print) = match( + BOOST_FIT_STATIC_LAMBDA_FUNCTION(print) = match( [](int x) { std::cout << "Integer: " << x << std::endl; @@ -96,7 +96,7 @@ Now, Fit provides two ways of doing overloading. The [`match`](match.md) adaptor However, when trying to do overloading involving something more generic, it can lead to ambiguities. So the [`conditional`](conditional.md) adaptor will pick the first function that is callable. This allows ordering the functions based on which one is more important. Say we would like to write a `print` function that can print not only using `cout` but can also print the values in ranges. We could write something like this: - FIT_STATIC_LAMBDA_FUNCTION(print) = conditional( + BOOST_FIT_STATIC_LAMBDA_FUNCTION(print) = conditional( [](const auto& x) -> decltype(std::cout << x, void()) { std::cout << x << std::endl; @@ -114,10 +114,10 @@ So the `-> decltype(std::cout << x, void())` will only make the function callabl using std::begin; template - auto adl_begin(R&& r) FIT_RETURNS(begin(r)); + auto adl_begin(R&& r) BOOST_FIT_RETURNS(begin(r)); } - FIT_STATIC_LAMBDA_FUNCTION(print) = conditional( + BOOST_FIT_STATIC_LAMBDA_FUNCTION(print) = conditional( [](const auto& x) -> decltype(std::cout << x, void()) { std::cout << x << std::endl; @@ -133,14 +133,14 @@ Tuples We could extend this to printing tuples as well. We will need to combine a couple of functions to make a `for_each_tuple`, which let us call a function for each element. First, the [`by`](by.md) adaptor will let us apply a function to each argument passed in, and the [`unpack`](unpack.md) adaptor will unpack the elements to a tuple and apply them to the argument: - FIT_STATIC_LAMBDA_FUNCTION(for_each_tuple) = [](const auto& sequence, auto f) + BOOST_FIT_STATIC_LAMBDA_FUNCTION(for_each_tuple) = [](const auto& sequence, auto f) { return unpack(by(f))(sequence); }; So now we can add an overload for tuples: - FIT_STATIC_LAMBDA_FUNCTION(print) = conditional( + BOOST_FIT_STATIC_LAMBDA_FUNCTION(print) = conditional( [](const auto& x) -> decltype(std::cout << x, void()) { std::cout << x << std::endl; @@ -165,7 +165,7 @@ Recursive Even though we are using lambdas, we can easily make this recursive using the [`fix`](fix.md) adaptor. This implements a fix point combinator, which passes the function(ie itself) in as the first argument, so we could write this: - FIT_STATIC_LAMBDA_FUNCTION(print) = fix(conditional( + BOOST_FIT_STATIC_LAMBDA_FUNCTION(print) = fix(conditional( [](auto, const auto& x) -> decltype(std::cout << x, void()) { std::cout << x << std::endl; @@ -185,7 +185,7 @@ Variadic We can also make this `print` function varidiac, so it prints every argument passed into it. We just rename our original `print` function to `simple_print`: - FIT_STATIC_LAMBDA_FUNCTION(simple_print) = fix(conditional( + BOOST_FIT_STATIC_LAMBDA_FUNCTION(simple_print) = fix(conditional( [](auto, const auto& x) -> decltype(std::cout << x, void()) { std::cout << x << std::endl; @@ -202,5 +202,5 @@ We can also make this `print` function varidiac, so it prints every argument pas And then apply the [`by`](by.md) adaptor to `simple_print`: - FIT_STATIC_LAMBDA_FUNCTION(print) = by(simple_print); + BOOST_FIT_STATIC_LAMBDA_FUNCTION(print) = by(simple_print); diff --git a/doc/src/requirements.md b/doc/src/requirements.md index 0306a9a..edc52e6 100644 --- a/doc/src/requirements.md +++ b/doc/src/requirements.md @@ -6,4 +6,4 @@ This requires a C++11 compiler. There are no third-party dependencies. This has Contexpr support ---------------- -Both MSVC and gcc 4.6 have limited constexpr support due to many bugs in the implementation of constexpr. However, constexpr initialization of functions is supported when using the `FIT_STATIC_FUNCTION` and `FIT_STATIC_LAMBDA_FUNCTION` constructs. +Both MSVC and gcc 4.6 have limited constexpr support due to many bugs in the implementation of constexpr. However, constexpr initialization of functions is supported when using the `BOOST_FIT_STATIC_FUNCTION` and `BOOST_FIT_STATIC_LAMBDA_FUNCTION` constructs. diff --git a/example/example.h b/example/example.h index 83bed4a..7929a0b 100644 --- a/example/example.h +++ b/example/example.h @@ -5,55 +5,55 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ -#ifndef FIT_GUARD_EXAMPLE_H -#define FIT_GUARD_EXAMPLE_H +#ifndef BOOST_FIT_GUARD_EXAMPLE_H +#define BOOST_FIT_GUARD_EXAMPLE_H -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include diff --git a/example/in.cpp b/example/in.cpp index 400054b..36edddf 100644 --- a/example/in.cpp +++ b/example/in.cpp @@ -7,15 +7,15 @@ #include "example.h" -using namespace fit; +using namespace boost::fit; #ifdef _MSC_VER template -auto member_find(const R& r, const T& x) FIT_RETURNS(r.find(x)); +auto member_find(const R& r, const T& x) BOOST_FIT_RETURNS(r.find(x)); #endif // Function to find an iterator using a containers built-in find if available -FIT_STATIC_LAMBDA_FUNCTION(find_iterator) = conditional( +BOOST_FIT_STATIC_LAMBDA_FUNCTION(find_iterator) = conditional( [](const std::string& s, const auto& x) { auto index = s.find(x); @@ -25,9 +25,9 @@ FIT_STATIC_LAMBDA_FUNCTION(find_iterator) = conditional( #ifdef _MSC_VER // On MSVC, trailing decltype doesn't work with generic lambdas, so a // seperate function can be used instead. - FIT_LIFT(member_find), + BOOST_FIT_LIFT(member_find), #else - [](const auto& r, const auto& x) FIT_RETURNS(r.find(x)), + [](const auto& r, const auto& x) BOOST_FIT_RETURNS(r.find(x)), #endif [](const auto& r, const auto& x) { @@ -37,7 +37,7 @@ FIT_STATIC_LAMBDA_FUNCTION(find_iterator) = conditional( } ); // Implement an infix `in` operator to check if a range contains an element -FIT_STATIC_LAMBDA_FUNCTION(in) = infix( +BOOST_FIT_STATIC_LAMBDA_FUNCTION(in) = infix( [](const auto& x, const auto& r) { using std::end; @@ -45,7 +45,7 @@ FIT_STATIC_LAMBDA_FUNCTION(in) = infix( } ); // Negate version of `in` -FIT_STATIC_LAMBDA_FUNCTION(not_in) = infix(compose(not _, in)); +BOOST_FIT_STATIC_LAMBDA_FUNCTION(not_in) = infix(compose(not _, in)); int main() { diff --git a/example/print.cpp b/example/print.cpp index 2e277fc..763bbb4 100644 --- a/example/print.cpp +++ b/example/print.cpp @@ -7,7 +7,7 @@ #include "example.h" -using namespace fit; +using namespace boost::fit; // ADL Lookup for ranges namespace adl { @@ -16,13 +16,13 @@ using std::begin; using std::end; template -auto adl_begin(R&& r) FIT_RETURNS(begin(r)); +auto adl_begin(R&& r) BOOST_FIT_RETURNS(begin(r)); template -auto adl_end(R&& r) FIT_RETURNS(end(r)); +auto adl_end(R&& r) BOOST_FIT_RETURNS(end(r)); } // Iterate over a tuple -FIT_STATIC_LAMBDA_FUNCTION(for_each_tuple) = [](const auto& sequence, auto f) +BOOST_FIT_STATIC_LAMBDA_FUNCTION(for_each_tuple) = [](const auto& sequence, auto f) { return unpack(by(f))(sequence); }; @@ -49,14 +49,14 @@ auto print_with_tuple(Self self, const T& tuple) -> decltype(for_each_tuple(tupl } // Recursively print everything -FIT_STATIC_FUNCTION(simple_print) = fix(conditional( - FIT_LIFT(print_with_cout), - FIT_LIFT(print_with_range), - FIT_LIFT(print_with_tuple) +BOOST_FIT_STATIC_FUNCTION(simple_print) = fix(conditional( + BOOST_FIT_LIFT(print_with_cout), + BOOST_FIT_LIFT(print_with_range), + BOOST_FIT_LIFT(print_with_tuple) )); #else // Recursively print everything -FIT_STATIC_LAMBDA_FUNCTION(simple_print) = fix(conditional( +BOOST_FIT_STATIC_LAMBDA_FUNCTION(simple_print) = fix(conditional( [](auto, const auto& x) -> decltype(std::cout << x, void()) { std::cout << x << std::endl; @@ -73,7 +73,7 @@ FIT_STATIC_LAMBDA_FUNCTION(simple_print) = fix(conditional( #endif // Make print function varidiac -FIT_STATIC_LAMBDA_FUNCTION(print) = by(simple_print); +BOOST_FIT_STATIC_LAMBDA_FUNCTION(print) = by(simple_print); int main() { diff --git a/example/sequence.cpp b/example/sequence.cpp index e10583b..85d95a6 100644 --- a/example/sequence.cpp +++ b/example/sequence.cpp @@ -8,29 +8,29 @@ #include "example.h" #include -using namespace fit; +using namespace boost::fit; // Transform each element of a tuple by calling f -FIT_STATIC_LAMBDA_FUNCTION(tuple_transform) = [](auto&& sequence, auto f) +BOOST_FIT_STATIC_LAMBDA_FUNCTION(tuple_transform) = [](auto&& sequence, auto f) { return unpack(by(f, construct()))(std::forward(sequence)); }; // Call f on each element of tuple -FIT_STATIC_LAMBDA_FUNCTION(tuple_for_each) = [](auto&& sequence, auto f) +BOOST_FIT_STATIC_LAMBDA_FUNCTION(tuple_for_each) = [](auto&& sequence, auto f) { return unpack(by(f))(std::forward(sequence)); }; // Fold over tuple using a f as the binary operator -FIT_STATIC_LAMBDA_FUNCTION(tuple_fold) = [](auto&& sequence, auto f) +BOOST_FIT_STATIC_LAMBDA_FUNCTION(tuple_fold) = [](auto&& sequence, auto f) { return unpack(compress(f))(std::forward(sequence)); }; // Concat multiple tuples -FIT_STATIC_FUNCTION(tuple_cat) = unpack(construct()); +BOOST_FIT_STATIC_FUNCTION(tuple_cat) = unpack(construct()); // Join a tuple of tuples into just a tuple -FIT_STATIC_FUNCTION(tuple_join) = unpack(tuple_cat); +BOOST_FIT_STATIC_FUNCTION(tuple_join) = unpack(tuple_cat); // Filter elements in a tuple using a predicate -FIT_STATIC_LAMBDA_FUNCTION(tuple_filter) = [](auto&& sequence, auto predicate) +BOOST_FIT_STATIC_LAMBDA_FUNCTION(tuple_filter) = [](auto&& sequence, auto predicate) { return compose(tuple_join, tuple_transform)( std::forward(sequence), @@ -44,7 +44,7 @@ FIT_STATIC_LAMBDA_FUNCTION(tuple_filter) = [](auto&& sequence, auto predicate) ); }; // Zip two tuples together -FIT_STATIC_LAMBDA_FUNCTION(tuple_zip_with) = [](auto&& sequence1, auto&& sequence2, auto f) +BOOST_FIT_STATIC_LAMBDA_FUNCTION(tuple_zip_with) = [](auto&& sequence1, auto&& sequence2, auto f) { auto&& functions = tuple_transform( std::forward(sequence1), @@ -60,7 +60,7 @@ FIT_STATIC_LAMBDA_FUNCTION(tuple_zip_with) = [](auto&& sequence1, auto&& sequenc return unpack(combined)(std::forward(sequence2)); }; // Dot product of a tuple -FIT_STATIC_LAMBDA_FUNCTION(tuple_dot) = [](auto&& a, auto&& b) +BOOST_FIT_STATIC_LAMBDA_FUNCTION(tuple_dot) = [](auto&& a, auto&& b) { auto product = tuple_zip_with(a, b, [](auto x, auto y) { return x*y; }); return tuple_fold(product, [](auto x, auto y) { return x+y; }); diff --git a/example/static_if.cpp b/example/static_if.cpp index 2f58133..93252ac 100644 --- a/example/static_if.cpp +++ b/example/static_if.cpp @@ -7,7 +7,7 @@ #include "example.h" -using namespace fit; +using namespace boost::fit; // static_if example taken from Baptiste Wicht: // http://baptiste-wicht.com/posts/2015/07/simulate-static_if-with-c11c14.html diff --git a/include/fit/alias.hpp b/include/boost/fit/alias.hpp similarity index 74% rename from include/fit/alias.hpp rename to include/boost/fit/alias.hpp index 8fef5a9..d783518 100644 --- a/include/fit/alias.hpp +++ b/include/boost/fit/alias.hpp @@ -5,13 +5,13 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ -#ifndef FIT_GUARD_ALIAS_H -#define FIT_GUARD_ALIAS_H +#ifndef BOOST_FIT_GUARD_ALIAS_H +#define BOOST_FIT_GUARD_ALIAS_H -#include -#include -#include -#include +#include +#include +#include +#include /// alias /// ===== @@ -57,7 +57,7 @@ #pragma warning(disable: 4579) #endif -namespace fit { +namespace boost { namespace fit { template struct alias_tag; @@ -90,23 +90,23 @@ constexpr const T& lvalue(const T& x) } -#define FIT_UNARY_PERFECT_ID(...) __VA_ARGS__ -#define FIT_UNARY_PERFECT_FOREACH(m) \ - m(const&, fit::detail::lvalue) \ - m(&, fit::detail::lvalue) \ - m(&&, fit::move) \ +#define BOOST_FIT_UNARY_PERFECT_ID(...) __VA_ARGS__ +#define BOOST_FIT_UNARY_PERFECT_FOREACH(m) \ + m(const&, boost::fit::detail::lvalue) \ + m(&, boost::fit::detail::lvalue) \ + m(&&, boost::fit::move) \ template struct alias { T value; - FIT_DELGATE_CONSTRUCTOR(alias, T, value) + BOOST_FIT_DELGATE_CONSTRUCTOR(alias, T, value) }; -#define FIT_DETAIL_ALIAS_GET_VALUE(ref, move) \ +#define BOOST_FIT_DETAIL_ALIAS_GET_VALUE(ref, move) \ template \ -constexpr auto alias_value(alias ref a, Ts&&...) FIT_RETURNS(move(a.value)) -FIT_UNARY_PERFECT_FOREACH(FIT_DETAIL_ALIAS_GET_VALUE) +constexpr auto alias_value(alias ref a, Ts&&...) BOOST_FIT_RETURNS(move(a.value)) +BOOST_FIT_UNARY_PERFECT_FOREACH(BOOST_FIT_DETAIL_ALIAS_GET_VALUE) template struct alias_tag> @@ -121,16 +121,16 @@ struct alias_inherit : T #endif { - FIT_INHERIT_CONSTRUCTOR(alias_inherit, T) + BOOST_FIT_INHERIT_CONSTRUCTOR(alias_inherit, T) }; -#define FIT_DETAIL_ALIAS_INHERIT_GET_VALUE(ref, move) \ -template::type> \ +#define BOOST_FIT_DETAIL_ALIAS_INHERIT_GET_VALUE(ref, move) \ +template::type> \ constexpr T ref alias_value(alias_inherit ref a, Ts&&...) \ { \ return move(a); \ } -FIT_UNARY_PERFECT_FOREACH(FIT_DETAIL_ALIAS_INHERIT_GET_VALUE) +BOOST_FIT_UNARY_PERFECT_FOREACH(BOOST_FIT_DETAIL_ALIAS_INHERIT_GET_VALUE) template struct alias_tag> @@ -146,9 +146,9 @@ struct alias_static_storage // member unitialized at runtime, it is, therefore, only safe to use this // class on types that are empty with constructors that have no possible // side effects. - static_assert(FIT_IS_EMPTY(T) && - FIT_IS_LITERAL(T) && - FIT_IS_DEFAULT_CONSTRUCTIBLE(T), "In-class initialization is not yet implemented on MSVC"); + static_assert(BOOST_FIT_IS_EMPTY(T) && + BOOST_FIT_IS_LITERAL(T) && + BOOST_FIT_IS_DEFAULT_CONSTRUCTIBLE(T), "In-class initialization is not yet implemented on MSVC"); #endif static constexpr T value = T(); }; @@ -161,7 +161,7 @@ constexpr T alias_static_storage::value; template struct alias_static { - template + template constexpr alias_static(Ts&&...) {} }; @@ -176,6 +176,6 @@ template struct alias_tag> { typedef Tag type; }; -} // namespace fit +}} // namespace boost::fit #endif diff --git a/include/fit/always.hpp b/include/boost/fit/always.hpp similarity index 75% rename from include/fit/always.hpp rename to include/boost/fit/always.hpp index 1aa2b03..4e02213 100644 --- a/include/fit/always.hpp +++ b/include/boost/fit/always.hpp @@ -5,11 +5,11 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ -#ifndef FIT_GUARD_FUNCTION_ALWAYS_H -#define FIT_GUARD_FUNCTION_ALWAYS_H +#ifndef BOOST_FIT_GUARD_FUNCTION_ALWAYS_H +#define BOOST_FIT_GUARD_FUNCTION_ALWAYS_H -#include -#include +#include +#include /// always /// ====== @@ -58,16 +58,16 @@ /// -#define FIT_NO_CONSTEXPR_VOID 1 -#ifndef FIT_NO_CONSTEXPR_VOID +#define BOOST_FIT_NO_CONSTEXPR_VOID 1 +#ifndef BOOST_FIT_NO_CONSTEXPR_VOID #ifdef __clang__ -#define FIT_NO_CONSTEXPR_VOID 0 +#define BOOST_FIT_NO_CONSTEXPR_VOID 0 #else -#define FIT_NO_CONSTEXPR_VOID 1 +#define BOOST_FIT_NO_CONSTEXPR_VOID 1 #endif #endif -namespace fit { namespace detail { +namespace boost { namespace fit { namespace detail { template struct always_base @@ -88,10 +88,10 @@ struct always_base } }; -#if FIT_NO_CONSTEXPR_VOID -#define FIT_ALWAYS_VOID_RETURN fit::detail::always_base::void_ +#if BOOST_FIT_NO_CONSTEXPR_VOID +#define BOOST_FIT_ALWAYS_VOID_RETURN boost::fit::detail::always_base::void_ #else -#define FIT_ALWAYS_VOID_RETURN void +#define BOOST_FIT_ALWAYS_VOID_RETURN void #endif template<> @@ -104,10 +104,10 @@ struct always_base struct void_ {}; template - constexpr FIT_ALWAYS_VOID_RETURN + constexpr BOOST_FIT_ALWAYS_VOID_RETURN operator()(As&&...) const { -#if FIT_NO_CONSTEXPR_VOID +#if BOOST_FIT_NO_CONSTEXPR_VOID return void_(); #endif } @@ -137,9 +137,9 @@ struct always_ref_f }; } -FIT_DECLARE_STATIC_VAR(always, detail::always_f); -FIT_DECLARE_STATIC_VAR(always_ref, detail::always_ref_f); +BOOST_FIT_DECLARE_STATIC_VAR(always, detail::always_f); +BOOST_FIT_DECLARE_STATIC_VAR(always_ref, detail::always_ref_f); -} // namespace fit +}} // namespace boost::fit #endif diff --git a/include/fit/apply.hpp b/include/boost/fit/apply.hpp similarity index 60% rename from include/fit/apply.hpp rename to include/boost/fit/apply.hpp index 9d6ed2f..aa9422d 100644 --- a/include/fit/apply.hpp +++ b/include/boost/fit/apply.hpp @@ -5,8 +5,8 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ -#ifndef FIT_GUARD_APPLY_H -#define FIT_GUARD_APPLY_H +#ifndef BOOST_FIT_GUARD_APPLY_H +#define BOOST_FIT_GUARD_APPLY_H /// apply /// ===== @@ -46,18 +46,18 @@ /// return x+y; /// } /// }; -/// assert(fit::apply(sum_f(), 1, 2) == 3); +/// assert(boost::fit::apply(sum_f(), 1, 2) == 3); /// -#include -#include -#include +#include +#include +#include -namespace fit { +namespace boost { namespace fit { namespace detail { -#if FIT_HAS_MANUAL_DEDUCTION || FIT_NO_EXPRESSION_SFINAE +#if BOOST_FIT_HAS_MANUAL_DEDUCTION || BOOST_FIT_NO_EXPRESSION_SFINAE struct apply_mem_fn { template @@ -71,19 +71,19 @@ struct apply_mem_fn : and_...> {}; -#define FIT_APPLY_MEM_FN_CALL(cv) \ +#define BOOST_FIT_APPLY_MEM_FN_CALL(cv) \ template ::type>, \ is_convertible_args, convertible_args> \ >::value>::type> \ constexpr R operator()(R (Base::*mf)(Ts...) cv, Derived&& ref, Us &&... xs) const \ { \ - return (FIT_FORWARD(Derived)(ref).*mf)(FIT_FORWARD(Us)(xs)...); \ + return (BOOST_FIT_FORWARD(Derived)(ref).*mf)(BOOST_FIT_FORWARD(Us)(xs)...); \ } - FIT_APPLY_MEM_FN_CALL() - FIT_APPLY_MEM_FN_CALL(const) - FIT_APPLY_MEM_FN_CALL(volatile) - FIT_APPLY_MEM_FN_CALL(const volatile) + BOOST_FIT_APPLY_MEM_FN_CALL() + BOOST_FIT_APPLY_MEM_FN_CALL(const) + BOOST_FIT_APPLY_MEM_FN_CALL(volatile) + BOOST_FIT_APPLY_MEM_FN_CALL(const volatile) }; struct apply_mem_data @@ -93,7 +93,7 @@ struct apply_mem_data )>::type> constexpr R operator()(R Base::*pmd, Derived&& ref) const { - return FIT_FORWARD(Derived)(ref).*pmd; + return BOOST_FIT_FORWARD(Derived)(ref).*pmd; } }; @@ -105,74 +105,74 @@ struct apply_deref struct apply_f { -#if FIT_HAS_MANUAL_DEDUCTION || FIT_NO_EXPRESSION_SFINAE +#if BOOST_FIT_HAS_MANUAL_DEDUCTION || BOOST_FIT_NO_EXPRESSION_SFINAE template::type>::value )>::type> - constexpr FIT_SFINAE_MANUAL_RESULT(apply_mem_fn, id_, id_, id_...) - operator()(F&& f, T&& obj, Ts&&... xs) const FIT_SFINAE_MANUAL_RETURNS + constexpr BOOST_FIT_SFINAE_MANUAL_RESULT(apply_mem_fn, id_, id_, id_...) + operator()(F&& f, T&& obj, Ts&&... xs) const BOOST_FIT_SFINAE_MANUAL_RETURNS ( - apply_mem_fn()(f, FIT_FORWARD(T)(obj), FIT_FORWARD(Ts)(xs)...) + apply_mem_fn()(f, BOOST_FIT_FORWARD(T)(obj), BOOST_FIT_FORWARD(Ts)(xs)...) ); template::type, class=typename std::enable_if<( std::is_member_function_pointer::type>::value )>::type> - constexpr FIT_SFINAE_MANUAL_RESULT(apply_mem_fn, id_, id_, id_...) - operator()(F&& f, T&& obj, Ts&&... xs) const FIT_SFINAE_MANUAL_RETURNS + constexpr BOOST_FIT_SFINAE_MANUAL_RESULT(apply_mem_fn, id_, id_, id_...) + operator()(F&& f, T&& obj, Ts&&... xs) const BOOST_FIT_SFINAE_MANUAL_RETURNS ( - apply_mem_fn()(f, *FIT_FORWARD(T)(obj), FIT_FORWARD(Ts)(xs)...) + apply_mem_fn()(f, *BOOST_FIT_FORWARD(T)(obj), BOOST_FIT_FORWARD(Ts)(xs)...) ); template::type>::value )>::type> - constexpr FIT_SFINAE_MANUAL_RESULT(apply_mem_data, id_, id_) - operator()(F&& f, T&& obj) const FIT_SFINAE_MANUAL_RETURNS + constexpr BOOST_FIT_SFINAE_MANUAL_RESULT(apply_mem_data, id_, id_) + operator()(F&& f, T&& obj) const BOOST_FIT_SFINAE_MANUAL_RETURNS ( - apply_mem_data()(f, FIT_FORWARD(T)(obj)) + apply_mem_data()(f, BOOST_FIT_FORWARD(T)(obj)) ); template::type, class=typename std::enable_if<( std::is_member_object_pointer::type>::value )>::type> - constexpr FIT_SFINAE_MANUAL_RESULT(apply_mem_data, id_, id_) - operator()(F&& f, T&& obj) const FIT_SFINAE_MANUAL_RETURNS + constexpr BOOST_FIT_SFINAE_MANUAL_RESULT(apply_mem_data, id_, id_) + operator()(F&& f, T&& obj) const BOOST_FIT_SFINAE_MANUAL_RETURNS ( - apply_mem_data()(f, *FIT_FORWARD(T)(obj)) + apply_mem_data()(f, *BOOST_FIT_FORWARD(T)(obj)) ); #else template constexpr auto operator()(T Base::*pmd, Derived&& ref) const - FIT_RETURNS(FIT_FORWARD(Derived)(ref).*pmd); + BOOST_FIT_RETURNS(BOOST_FIT_FORWARD(Derived)(ref).*pmd); template constexpr auto operator()(PMD&& pmd, Pointer&& ptr) const - FIT_RETURNS((*FIT_FORWARD(Pointer)(ptr)).*FIT_FORWARD(PMD)(pmd)); + BOOST_FIT_RETURNS((*BOOST_FIT_FORWARD(Pointer)(ptr)).*BOOST_FIT_FORWARD(PMD)(pmd)); template constexpr auto operator()(T Base::*pmf, Derived&& ref, Args&&... args) const - FIT_RETURNS((FIT_FORWARD(Derived)(ref).*pmf)(FIT_FORWARD(Args)(args)...)); + BOOST_FIT_RETURNS((BOOST_FIT_FORWARD(Derived)(ref).*pmf)(BOOST_FIT_FORWARD(Args)(args)...)); template constexpr auto operator()(PMF&& pmf, Pointer&& ptr, Args&&... args) const - FIT_RETURNS(((*FIT_FORWARD(Pointer)(ptr)).*FIT_FORWARD(PMF)(pmf))(FIT_FORWARD(Args)(args)...)); + BOOST_FIT_RETURNS(((*BOOST_FIT_FORWARD(Pointer)(ptr)).*BOOST_FIT_FORWARD(PMF)(pmf))(BOOST_FIT_FORWARD(Args)(args)...)); #endif template - constexpr FIT_SFINAE_RESULT(F, id_...) - operator()(F&& f, Ts&&... xs) const FIT_SFINAE_RETURNS + constexpr BOOST_FIT_SFINAE_RESULT(F, id_...) + operator()(F&& f, Ts&&... xs) const BOOST_FIT_SFINAE_RETURNS ( - f(FIT_FORWARD(Ts)(xs)...) + f(BOOST_FIT_FORWARD(Ts)(xs)...) ); }; } -FIT_DECLARE_STATIC_VAR(apply, detail::apply_f); +BOOST_FIT_DECLARE_STATIC_VAR(apply, detail::apply_f); -} // namespace fit +}} // namespace boost::fit #endif diff --git a/include/fit/apply_eval.hpp b/include/boost/fit/apply_eval.hpp similarity index 64% rename from include/fit/apply_eval.hpp rename to include/boost/fit/apply_eval.hpp index 4f58d3a..49adb03 100644 --- a/include/fit/apply_eval.hpp +++ b/include/boost/fit/apply_eval.hpp @@ -5,8 +5,8 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ -#ifndef FIT_GUARD_APPLY_EVAL_H -#define FIT_GUARD_APPLY_EVAL_H +#ifndef BOOST_FIT_GUARD_APPLY_EVAL_H +#define BOOST_FIT_GUARD_APPLY_EVAL_H /// apply_eval /// ========== @@ -51,33 +51,33 @@ /// return x+y; /// } /// }; -/// assert(fit::apply_eval(sum_f(), []{ return 1; }, []{ return 2; }) == 3); +/// assert(boost::fit::apply_eval(sum_f(), []{ return 1; }, []{ return 2; }) == 3); /// -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include -#ifndef FIT_NO_ORDERED_BRACE_INIT +#ifndef BOOST_FIT_NO_ORDERED_BRACE_INIT #if (defined(__GNUC__) && !defined (__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ < 9) || defined(_MSC_VER) -#define FIT_NO_ORDERED_BRACE_INIT 1 +#define BOOST_FIT_NO_ORDERED_BRACE_INIT 1 #else -#define FIT_NO_ORDERED_BRACE_INIT 0 +#define BOOST_FIT_NO_ORDERED_BRACE_INIT 0 #endif #endif -#if FIT_NO_ORDERED_BRACE_INIT -#include -#include +#if BOOST_FIT_NO_ORDERED_BRACE_INIT +#include +#include #endif -namespace fit { +namespace boost { namespace fit { namespace detail { -#if FIT_NO_ORDERED_BRACE_INIT +#if BOOST_FIT_NO_ORDERED_BRACE_INIT template constexpr R eval_ordered(const F& f, Pack&& p) { @@ -87,7 +87,7 @@ constexpr R eval_ordered(const F& f, Pack&& p) template constexpr R eval_ordered(const F& f, Pack&& p, T&& x, Ts&&... xs) { - return eval_ordered(f, pack_join(FIT_FORWARD(Pack)(p), fit::pack_forward(fit::eval(x))), FIT_FORWARD(Ts)(xs)...); + return eval_ordered(f, pack_join(BOOST_FIT_FORWARD(Pack)(p), boost::fit::pack_forward(boost::fit::eval(x))), BOOST_FIT_FORWARD(Ts)(xs)...); } #else template @@ -96,7 +96,7 @@ struct eval_helper R result; template - constexpr eval_helper(const F& f, Ts&&... xs) : result(apply(f, FIT_FORWARD(Ts)(xs)...)) + constexpr eval_helper(const F& f, Ts&&... xs) : result(apply(f, BOOST_FIT_FORWARD(Ts)(xs)...)) {} constexpr R get_result() @@ -110,7 +110,7 @@ struct eval_helper { int x; template - constexpr eval_helper(const F& f, Ts&&... xs) : x(apply(f, FIT_FORWARD(Ts)(xs)...), 0) + constexpr eval_helper(const F& f, Ts&&... xs) : x(apply(f, BOOST_FIT_FORWARD(Ts)(xs)...), 0) {} }; #endif @@ -118,24 +118,24 @@ struct eval_helper struct apply_eval_f { template(), fit::eval(std::declval())...) + apply(std::declval(), boost::fit::eval(std::declval())...) ), class=typename std::enable_if<(!std::is_void::value)>::type > constexpr R operator()(const F& f, Ts&&... xs) const { return -#if FIT_NO_ORDERED_BRACE_INIT +#if BOOST_FIT_NO_ORDERED_BRACE_INIT eval_ordered - (f, pack(), FIT_FORWARD(Ts)(xs)...); + (f, pack(), BOOST_FIT_FORWARD(Ts)(xs)...); #else eval_helper - {f, fit::eval(FIT_FORWARD(Ts)(xs))...}.get_result(); + {f, boost::fit::eval(BOOST_FIT_FORWARD(Ts)(xs))...}.get_result(); #endif } template(), fit::eval(std::declval())...) + apply(std::declval(), boost::fit::eval(std::declval())...) ), class=typename std::enable_if<(std::is_void::value)>::type > @@ -143,20 +143,20 @@ struct apply_eval_f operator()(const F& f, Ts&&... xs) const { return (typename detail::holder::type) -#if FIT_NO_ORDERED_BRACE_INIT +#if BOOST_FIT_NO_ORDERED_BRACE_INIT eval_ordered - (f, pack(), FIT_FORWARD(Ts)(xs)...); + (f, pack(), BOOST_FIT_FORWARD(Ts)(xs)...); #else eval_helper - {f, fit::eval(FIT_FORWARD(Ts)(xs))...}; + {f, boost::fit::eval(BOOST_FIT_FORWARD(Ts)(xs))...}; #endif } }; } -FIT_DECLARE_STATIC_VAR(apply_eval, detail::apply_eval_f); +BOOST_FIT_DECLARE_STATIC_VAR(apply_eval, detail::apply_eval_f); -} // namespace fit +}} // namespace boost::fit #endif diff --git a/include/fit/arg.hpp b/include/boost/fit/arg.hpp similarity index 71% rename from include/fit/arg.hpp rename to include/boost/fit/arg.hpp index cc16485..857e715 100644 --- a/include/fit/arg.hpp +++ b/include/boost/fit/arg.hpp @@ -5,12 +5,12 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ -#ifndef FIT_GUARD_FUNCTION_ARGS_H -#define FIT_GUARD_FUNCTION_ARGS_H +#ifndef BOOST_FIT_GUARD_FUNCTION_ARGS_H +#define BOOST_FIT_GUARD_FUNCTION_ARGS_H -#include -#include -#include +#include +#include +#include #include /// arg @@ -39,7 +39,7 @@ /// assert(arg(std::integral_constant())(1,2,3,4,5) == 3); /// -namespace fit { +namespace boost { namespace fit { namespace detail { @@ -48,14 +48,14 @@ struct perfect_ref { typedef T&& type; T&& value; - constexpr perfect_ref(T&& x) : value(FIT_FORWARD(T)(x)) + constexpr perfect_ref(T&& x) : value(BOOST_FIT_FORWARD(T)(x)) {} }; template constexpr perfect_ref make_perfect_ref(T&& x) { - return { FIT_FORWARD(T)(x) }; + return { BOOST_FIT_FORWARD(T)(x) }; } template @@ -71,7 +71,7 @@ struct args_at { template constexpr auto operator()(ignore..., T x, Ts...) const - FIT_RETURNS(FIT_FORWARD(typename T::type)(x.value)); + BOOST_FIT_RETURNS(BOOST_FIT_FORWARD(typename T::type)(x.value)); }; template @@ -81,18 +81,18 @@ constexpr args_at make_args_at(seq) } template -constexpr auto get_args(Ts&&... xs) FIT_RETURNS +constexpr auto get_args(Ts&&... xs) BOOST_FIT_RETURNS ( - make_args_at(typename gens::type())(nullptr, make_perfect_ref(FIT_FORWARD(Ts)(xs))...) + make_args_at(typename gens::type())(nullptr, make_perfect_ref(BOOST_FIT_FORWARD(Ts)(xs))...) ); template struct make_args_f { template - constexpr auto operator()(Ts&&... xs) const FIT_RETURNS + constexpr auto operator()(Ts&&... xs) const BOOST_FIT_RETURNS ( - get_args(FIT_FORWARD(Ts)(xs)...) + get_args(BOOST_FIT_FORWARD(Ts)(xs)...) ); }; @@ -108,13 +108,13 @@ struct arg_f } template -constexpr auto arg_c(Ts&&... xs) FIT_RETURNS +constexpr auto arg_c(Ts&&... xs) BOOST_FIT_RETURNS ( - detail::get_args(FIT_FORWARD(Ts)(xs)...) + detail::get_args(BOOST_FIT_FORWARD(Ts)(xs)...) ); -FIT_DECLARE_STATIC_VAR(arg, detail::arg_f); +BOOST_FIT_DECLARE_STATIC_VAR(arg, detail::arg_f); -} // namespace fit +}} // namespace boost::fit #endif diff --git a/include/fit/by.hpp b/include/boost/fit/by.hpp similarity index 59% rename from include/fit/by.hpp rename to include/boost/fit/by.hpp index 8ec13e6..d09f83e 100644 --- a/include/fit/by.hpp +++ b/include/boost/fit/by.hpp @@ -5,8 +5,8 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ -#ifndef FIT_GUARD_FUNCTION_ON_H -#define FIT_GUARD_FUNCTION_ON_H +#ifndef BOOST_FIT_GUARD_FUNCTION_ON_H +#define BOOST_FIT_GUARD_FUNCTION_ON_H /// by /// == @@ -60,21 +60,21 @@ /// {} /// int x; /// }; -/// assert(fit::by(&foo::x, _ + _)(foo(1), foo(2)) == 3); +/// assert(boost::fit::by(&foo::x, _ + _)(foo(1), foo(2)) == 3); /// #include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include -namespace fit { +namespace boost { namespace fit { namespace detail { @@ -85,17 +85,17 @@ struct project_eval const Projection& p; template - constexpr project_eval(X&& xp, const P& pp) : x(FIT_FORWARD(X)(xp)), p(pp) + constexpr project_eval(X&& xp, const P& pp) : x(BOOST_FIT_FORWARD(X)(xp)), p(pp) {} - constexpr auto operator()() const FIT_RETURNS - (p(FIT_FORWARD(T)(x))); + constexpr auto operator()() const BOOST_FIT_RETURNS + (p(BOOST_FIT_FORWARD(T)(x))); }; template constexpr project_eval make_project_eval(T&& x, const Projection& p) { - return project_eval(FIT_FORWARD(T)(x), p); + return project_eval(BOOST_FIT_FORWARD(T)(x), p); } template @@ -105,21 +105,21 @@ struct project_void_eval const Projection& p; template - constexpr project_void_eval(X&& xp, const P& pp) : x(FIT_FORWARD(X)(xp)), p(pp) + constexpr project_void_eval(X&& xp, const P& pp) : x(BOOST_FIT_FORWARD(X)(xp)), p(pp) {} struct void_ {}; constexpr void_ operator()() const { - return p(FIT_FORWARD(T)(x)), void_(); + return p(BOOST_FIT_FORWARD(T)(x)), void_(); } }; template constexpr project_void_eval make_project_void_eval(T&& x, const Projection& p) { - return project_void_eval(FIT_FORWARD(T)(x), p); + return project_void_eval(BOOST_FIT_FORWARD(T)(x), p); } template constexpr R by_eval(const Projection& p, const F& f, Ts&&... xs) { - return apply_eval(f, make_project_eval(FIT_FORWARD(Ts)(xs), p)...); + return apply_eval(f, make_project_eval(BOOST_FIT_FORWARD(Ts)(xs), p)...); } -#if FIT_NO_ORDERED_BRACE_INIT -#define FIT_BY_VOID_RETURN FIT_ALWAYS_VOID_RETURN +#if BOOST_FIT_NO_ORDERED_BRACE_INIT +#define BOOST_FIT_BY_VOID_RETURN BOOST_FIT_ALWAYS_VOID_RETURN #else -#if FIT_NO_CONSTEXPR_VOID -#define FIT_BY_VOID_RETURN fit::detail::swallow +#if BOOST_FIT_NO_CONSTEXPR_VOID +#define BOOST_FIT_BY_VOID_RETURN boost::fit::detail::swallow #else -#define FIT_BY_VOID_RETURN void +#define BOOST_FIT_BY_VOID_RETURN void #endif #endif template -constexpr FIT_ALWAYS_VOID_RETURN by_void_eval(const Projection& p, Ts&&... xs) +constexpr BOOST_FIT_ALWAYS_VOID_RETURN by_void_eval(const Projection& p, Ts&&... xs) { - return apply_eval(always(), make_project_void_eval(FIT_FORWARD(Ts)(xs), p)...); + return apply_eval(always(), make_project_void_eval(BOOST_FIT_FORWARD(Ts)(xs), p)...); } struct swallow @@ -191,23 +191,23 @@ struct by_adaptor : detail::callable_base, detail::callable_base : failure_map> {}; - FIT_INHERIT_DEFAULT(by_adaptor, detail::callable_base, F) + BOOST_FIT_INHERIT_DEFAULT(by_adaptor, detail::callable_base, F) - template), FIT_ENABLE_IF_CONVERTIBLE(G, detail::callable_base)> + template), BOOST_FIT_ENABLE_IF_CONVERTIBLE(G, detail::callable_base)> constexpr by_adaptor(P&& p, G&& f) - : detail::callable_base(FIT_FORWARD(P)(p)), detail::callable_base(FIT_FORWARD(G)(f)) + : detail::callable_base(BOOST_FIT_FORWARD(P)(p)), detail::callable_base(BOOST_FIT_FORWARD(G)(f)) {} - FIT_RETURNS_CLASS(by_adaptor); + BOOST_FIT_RETURNS_CLASS(by_adaptor); template - constexpr FIT_SFINAE_RESULT(const detail::callable_base&, result_of&, id_>...) - operator()(Ts&&... xs) const FIT_SFINAE_RETURNS + constexpr BOOST_FIT_SFINAE_RESULT(const detail::callable_base&, result_of&, id_>...) + operator()(Ts&&... xs) const BOOST_FIT_SFINAE_RETURNS ( detail::by_eval( - FIT_MANGLE_CAST(const detail::callable_base&)(FIT_CONST_THIS->base_projection(xs...)), - FIT_MANGLE_CAST(const detail::callable_base&)(FIT_CONST_THIS->base_function(xs...)), - FIT_FORWARD(Ts)(xs)... + BOOST_FIT_MANGLE_CAST(const detail::callable_base&)(BOOST_FIT_CONST_THIS->base_projection(xs...)), + BOOST_FIT_MANGLE_CAST(const detail::callable_base&)(BOOST_FIT_CONST_THIS->base_function(xs...)), + BOOST_FIT_FORWARD(Ts)(xs)... ) ); }; @@ -222,32 +222,32 @@ struct by_adaptor : detail::callable_base return always_ref(*this)(xs...); } - FIT_INHERIT_DEFAULT(by_adaptor, detail::callable_base) + BOOST_FIT_INHERIT_DEFAULT(by_adaptor, detail::callable_base) - template)> + template)> constexpr by_adaptor(P&& p) - : detail::callable_base(FIT_FORWARD(P)(p)) + : detail::callable_base(BOOST_FIT_FORWARD(P)(p)) {} - FIT_RETURNS_CLASS(by_adaptor); + BOOST_FIT_RETURNS_CLASS(by_adaptor); template - constexpr FIT_BY_VOID_RETURN operator()(Ts&&... xs) const + constexpr BOOST_FIT_BY_VOID_RETURN operator()(Ts&&... xs) const { -#if FIT_NO_ORDERED_BRACE_INIT - return detail::by_void_eval(this->base_projection(xs...), FIT_FORWARD(Ts)(xs)...); +#if BOOST_FIT_NO_ORDERED_BRACE_INIT + return detail::by_void_eval(this->base_projection(xs...), BOOST_FIT_FORWARD(Ts)(xs)...); #else -#if FIT_NO_CONSTEXPR_VOID +#if BOOST_FIT_NO_CONSTEXPR_VOID return #endif detail::swallow{ - (this->base_projection(xs...)(FIT_FORWARD(Ts)(xs)), 0)... + (this->base_projection(xs...)(BOOST_FIT_FORWARD(Ts)(xs)), 0)... }; #endif } }; -FIT_DECLARE_STATIC_VAR(by, detail::make); +BOOST_FIT_DECLARE_STATIC_VAR(by, detail::make); -} // namespace fit +}} // namespace boost::fit #endif diff --git a/include/fit/capture.hpp b/include/boost/fit/capture.hpp similarity index 64% rename from include/fit/capture.hpp rename to include/boost/fit/capture.hpp index c43a4e2..4538ff5 100644 --- a/include/fit/capture.hpp +++ b/include/boost/fit/capture.hpp @@ -5,14 +5,14 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ -#ifndef FIT_GUARD_CAPTURE_H -#define FIT_GUARD_CAPTURE_H +#ifndef BOOST_FIT_GUARD_CAPTURE_H +#define BOOST_FIT_GUARD_CAPTURE_H -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include /// capture /// ======= @@ -58,11 +58,11 @@ /// return x+y; /// } /// }; -/// auto add_one = fit::capture(1)(sum_f()); +/// auto add_one = boost::fit::capture(1)(sum_f()); /// assert(add_one(2) == 3); /// -namespace fit { +namespace boost { namespace fit { namespace detail { @@ -71,7 +71,7 @@ struct capture_invoke : detail::callable_base, Pack { typedef capture_invoke fit_rewritable1_tag; template - constexpr capture_invoke(X&& x, Y&& y) : detail::callable_base(FIT_FORWARD(X)(x)), Pack(FIT_FORWARD(Y)(y)) + constexpr capture_invoke(X&& x, Y&& y) : detail::callable_base(BOOST_FIT_FORWARD(X)(x)), Pack(BOOST_FIT_FORWARD(Y)(y)) {} template constexpr const detail::callable_base& base_function(Ts&&... xs) const @@ -111,42 +111,42 @@ struct capture_invoke : detail::callable_base, Pack : failure_map> {}; - FIT_RETURNS_CLASS(capture_invoke); + BOOST_FIT_RETURNS_CLASS(capture_invoke); template - constexpr FIT_SFINAE_RESULT + constexpr BOOST_FIT_SFINAE_RESULT ( - typename result_of, - result_of...> + result_of...> >::type, id_&&> ) - operator()(Ts&&... xs) const FIT_SFINAE_RETURNS + operator()(Ts&&... xs) const BOOST_FIT_SFINAE_RETURNS ( - fit::pack_join + boost::fit::pack_join ( - FIT_MANGLE_CAST(const Pack&)(FIT_CONST_THIS->get_pack(xs...)), - fit::pack_forward(FIT_FORWARD(Ts)(xs)...) + BOOST_FIT_MANGLE_CAST(const Pack&)(BOOST_FIT_CONST_THIS->get_pack(xs...)), + boost::fit::pack_forward(BOOST_FIT_FORWARD(Ts)(xs)...) ) - (FIT_RETURNS_C_CAST(detail::callable_base&&)(FIT_CONST_THIS->base_function(xs...))) + (BOOST_FIT_RETURNS_C_CAST(detail::callable_base&&)(BOOST_FIT_CONST_THIS->base_function(xs...))) ); }; template struct capture_pack : Pack { - FIT_INHERIT_CONSTRUCTOR(capture_pack, Pack); + BOOST_FIT_INHERIT_CONSTRUCTOR(capture_pack, Pack); - FIT_RETURNS_CLASS(capture_pack); + BOOST_FIT_RETURNS_CLASS(capture_pack); // TODO: Should use rvalue ref qualifier template - constexpr auto operator()(F f) const FIT_SFINAE_RETURNS + constexpr auto operator()(F f) const BOOST_FIT_SFINAE_RETURNS ( - capture_invoke(FIT_RETURNS_STATIC_CAST(F&&)(f), - FIT_RETURNS_C_CAST(Pack&&)( - FIT_RETURNS_STATIC_CAST(const Pack&)(*always(FIT_CONST_THIS)(f)) + capture_invoke(BOOST_FIT_RETURNS_STATIC_CAST(F&&)(f), + BOOST_FIT_RETURNS_C_CAST(Pack&&)( + BOOST_FIT_RETURNS_STATIC_CAST(const Pack&)(*always(BOOST_FIT_CONST_THIS)(f)) ) ) ); @@ -165,17 +165,17 @@ template struct capture_f { template - constexpr auto operator()(Ts&&... xs) const FIT_RETURNS + constexpr auto operator()(Ts&&... xs) const BOOST_FIT_RETURNS ( - FIT_RETURNS_CONSTRUCT(make_capture_pack_f)()(FIT_RETURNS_CONSTRUCT(F)()(FIT_FORWARD(Ts)(xs)...)) + BOOST_FIT_RETURNS_CONSTRUCT(make_capture_pack_f)()(BOOST_FIT_RETURNS_CONSTRUCT(F)()(BOOST_FIT_FORWARD(Ts)(xs)...)) ); }; } -FIT_DECLARE_STATIC_VAR(capture, detail::capture_f); -FIT_DECLARE_STATIC_VAR(capture_forward, detail::capture_f); -FIT_DECLARE_STATIC_VAR(capture_decay, detail::capture_f); +BOOST_FIT_DECLARE_STATIC_VAR(capture, detail::capture_f); +BOOST_FIT_DECLARE_STATIC_VAR(capture_forward, detail::capture_f); +BOOST_FIT_DECLARE_STATIC_VAR(capture_decay, detail::capture_f); -} // namespace fit +}} // namespace boost::fit #endif diff --git a/include/fit/combine.hpp b/include/boost/fit/combine.hpp similarity index 63% rename from include/fit/combine.hpp rename to include/boost/fit/combine.hpp index 255ad70..355a50c 100644 --- a/include/fit/combine.hpp +++ b/include/boost/fit/combine.hpp @@ -5,8 +5,8 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ -#ifndef FIT_GUARD_COMBINE_H -#define FIT_GUARD_COMBINE_H +#ifndef BOOST_FIT_GUARD_COMBINE_H +#define BOOST_FIT_GUARD_COMBINE_H /// combine /// ======= @@ -40,19 +40,19 @@ /// Example /// ------- /// -/// auto f = fit::combine( -/// fit::construct(), -/// fit::capture(1)(fit::construct()), -/// fit::capture(2)(fit::construct())); +/// auto f = boost::fit::combine( +/// boost::fit::construct(), +/// boost::fit::capture(1)(boost::fit::construct()), +/// boost::fit::capture(2)(boost::fit::construct())); /// assert(f(3, 7) == std::make_tuple(std::make_pair(1, 3), std::make_pair(2, 7))); /// -#include -#include -#include -#include +#include +#include +#include +#include -namespace fit { namespace detail { +namespace boost { namespace fit { namespace detail { template struct combine_adaptor_base; @@ -63,13 +63,13 @@ struct combine_adaptor_base, F, Gs...> { typedef pack_base, Gs...> base_type; - FIT_INHERIT_DEFAULT(combine_adaptor_base, base_type, F) + BOOST_FIT_INHERIT_DEFAULT(combine_adaptor_base, base_type, F) template + BOOST_FIT_ENABLE_IF_CONSTRUCTIBLE(F, X), + BOOST_FIT_ENABLE_IF_CONSTRUCTIBLE(base_type, Xs...)> constexpr combine_adaptor_base(X&& x, Xs&&... xs) - : F(FIT_FORWARD(X)(x)), base_type(FIT_FORWARD(Xs)(xs)...) + : F(BOOST_FIT_FORWARD(X)(x)), base_type(BOOST_FIT_FORWARD(Xs)(xs)...) {} template @@ -78,11 +78,11 @@ struct combine_adaptor_base, F, Gs...> return always_ref(*this)(xs...); } - FIT_RETURNS_CLASS(combine_adaptor_base); + BOOST_FIT_RETURNS_CLASS(combine_adaptor_base); // Result needs to be calculated in a separate class to avoid confusing the // compiler on MSVC -#if FIT_NO_EXPRESSION_SFINAE || FIT_HAS_MANUAL_DEDUCTION +#if BOOST_FIT_NO_EXPRESSION_SFINAE || BOOST_FIT_HAS_MANUAL_DEDUCTION template struct combine_result : result_of>...> @@ -90,15 +90,15 @@ struct combine_adaptor_base, F, Gs...> #endif template -#if FIT_NO_EXPRESSION_SFINAE || FIT_HAS_MANUAL_DEDUCTION +#if BOOST_FIT_NO_EXPRESSION_SFINAE || BOOST_FIT_HAS_MANUAL_DEDUCTION constexpr typename combine_result::type #else constexpr auto #endif - operator()(Ts&&... xs) const FIT_SFINAE_MANUAL_RETURNS + operator()(Ts&&... xs) const BOOST_FIT_SFINAE_MANUAL_RETURNS ( - (FIT_MANGLE_CAST(const F&)(FIT_CONST_THIS->base_function(xs...))) - (alias_value, Gs...>, Gs>(*FIT_CONST_THIS, xs)(FIT_FORWARD(Ts)(xs))...) + (BOOST_FIT_MANGLE_CAST(const F&)(BOOST_FIT_CONST_THIS->base_function(xs...))) + (alias_value, Gs...>, Gs>(*BOOST_FIT_CONST_THIS, xs)(BOOST_FIT_FORWARD(Ts)(xs))...) ); }; @@ -109,11 +109,11 @@ struct combine_adaptor : detail::combine_adaptor_base::type, detail::callable_base, detail::callable_base...> { typedef detail::combine_adaptor_base::type, detail::callable_base, detail::callable_base...> base_type; - FIT_INHERIT_CONSTRUCTOR(combine_adaptor, base_type) + BOOST_FIT_INHERIT_CONSTRUCTOR(combine_adaptor, base_type) }; -FIT_DECLARE_STATIC_VAR(combine, detail::make); +BOOST_FIT_DECLARE_STATIC_VAR(combine, detail::make); -} // namespace fit +}} // namespace boost::fit #endif diff --git a/include/fit/compose.hpp b/include/boost/fit/compose.hpp similarity index 59% rename from include/fit/compose.hpp rename to include/boost/fit/compose.hpp index 89e66a9..b1b3581 100644 --- a/include/fit/compose.hpp +++ b/include/boost/fit/compose.hpp @@ -5,8 +5,8 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ -#ifndef FIT_GUARD_FUNCTION_COMPOSE_H -#define FIT_GUARD_FUNCTION_COMPOSE_H +#ifndef BOOST_FIT_GUARD_FUNCTION_COMPOSE_H +#define BOOST_FIT_GUARD_FUNCTION_COMPOSE_H /// compose /// ======= @@ -64,60 +64,60 @@ /// assert(r == 4); /// -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include -#include -#include -#include +#include +#include +#include -namespace fit { namespace detail { +namespace boost { namespace fit { namespace detail { template struct compose_kernel : detail::compressed_pair { typedef detail::compressed_pair base_type; - FIT_INHERIT_CONSTRUCTOR(compose_kernel, base_type) + BOOST_FIT_INHERIT_CONSTRUCTOR(compose_kernel, base_type) - FIT_RETURNS_CLASS(compose_kernel); + BOOST_FIT_RETURNS_CLASS(compose_kernel); template - constexpr FIT_SFINAE_RESULT(const F1&, result_of...>) - operator()(Ts&&... xs) const FIT_SFINAE_RETURNS + constexpr BOOST_FIT_SFINAE_RESULT(const F1&, result_of...>) + operator()(Ts&&... xs) const BOOST_FIT_SFINAE_RETURNS ( - FIT_MANGLE_CAST(const F1&)(FIT_CONST_THIS->first(xs...))( - FIT_MANGLE_CAST(const F2&)(FIT_CONST_THIS->second(xs...))(FIT_FORWARD(Ts)(xs)...) + BOOST_FIT_MANGLE_CAST(const F1&)(BOOST_FIT_CONST_THIS->first(xs...))( + BOOST_FIT_MANGLE_CAST(const F2&)(BOOST_FIT_CONST_THIS->second(xs...))(BOOST_FIT_FORWARD(Ts)(xs)...) ) ); }; } template -struct compose_adaptor : detail::compose_kernel, FIT_JOIN(compose_adaptor, detail::callable_base...)> +struct compose_adaptor : detail::compose_kernel, BOOST_FIT_JOIN(compose_adaptor, detail::callable_base...)> { typedef compose_adaptor fit_rewritable_tag; - typedef FIT_JOIN(compose_adaptor, detail::callable_base...) tail; + typedef BOOST_FIT_JOIN(compose_adaptor, detail::callable_base...) tail; typedef detail::compose_kernel, tail> base_type; - FIT_INHERIT_DEFAULT(compose_adaptor, base_type) + BOOST_FIT_INHERIT_DEFAULT(compose_adaptor, base_type) template, X), - FIT_ENABLE_IF_CONSTRUCTIBLE(tail, Xs...) + BOOST_FIT_ENABLE_IF_CONSTRUCTIBLE(detail::callable_base, X), + BOOST_FIT_ENABLE_IF_CONSTRUCTIBLE(tail, Xs...) > constexpr compose_adaptor(X&& f1, Xs&& ... fs) - : base_type(FIT_FORWARD(X)(f1), tail(FIT_FORWARD(Xs)(fs)...)) + : base_type(BOOST_FIT_FORWARD(X)(f1), tail(BOOST_FIT_FORWARD(Xs)(fs)...)) {} template, X) + BOOST_FIT_ENABLE_IF_CONSTRUCTIBLE(detail::callable_base, X) > constexpr compose_adaptor(X&& f1) - : base_type(FIT_FORWARD(X)(f1)) + : base_type(BOOST_FIT_FORWARD(X)(f1)) {} }; @@ -126,11 +126,11 @@ struct compose_adaptor : detail::callable_base { typedef compose_adaptor fit_rewritable_tag; - FIT_INHERIT_DEFAULT(compose_adaptor, detail::callable_base) + BOOST_FIT_INHERIT_DEFAULT(compose_adaptor, detail::callable_base) - template)> + template)> constexpr compose_adaptor(X&& f1) - : detail::callable_base(FIT_FORWARD(X)(f1)) + : detail::callable_base(BOOST_FIT_FORWARD(X)(f1)) {} }; @@ -142,11 +142,11 @@ struct compose_adaptor typedef compose_adaptor fit_rewritable_tag; typedef detail::compose_kernel, detail::callable_base> base_type; - FIT_INHERIT_CONSTRUCTOR(compose_adaptor, base_type) + BOOST_FIT_INHERIT_CONSTRUCTOR(compose_adaptor, base_type) }; -FIT_DECLARE_STATIC_VAR(compose, detail::make); +BOOST_FIT_DECLARE_STATIC_VAR(compose, detail::make); -} // namespace fit +}} // namespace boost::fit #endif diff --git a/include/fit/compress.hpp b/include/boost/fit/compress.hpp similarity index 62% rename from include/fit/compress.hpp rename to include/boost/fit/compress.hpp index 4476f73..470cd2a 100644 --- a/include/fit/compress.hpp +++ b/include/boost/fit/compress.hpp @@ -5,8 +5,8 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ -#ifndef FIT_GUARD_COMPRESS_H -#define FIT_GUARD_COMPRESS_H +#ifndef BOOST_FIT_GUARD_COMPRESS_H +#define BOOST_FIT_GUARD_COMPRESS_H /// compress /// ======== @@ -63,32 +63,32 @@ /// return x > y ? x : y; /// } /// }; -/// assert(fit::compress(max_f())(2, 3, 4, 5) == 5); +/// assert(boost::fit::compress(max_f())(2, 3, 4, 5) == 5); /// -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include -namespace fit { namespace detail { +namespace boost { namespace fit { namespace detail { struct v_fold { - FIT_RETURNS_CLASS(v_fold); + BOOST_FIT_RETURNS_CLASS(v_fold); template - constexpr FIT_SFINAE_MANUAL_RESULT(const v_fold&, id_, result_of, id_>, id_...) - operator()(const F& f, State&& state, T&& x, Ts&&... xs) const FIT_SFINAE_MANUAL_RETURNS + constexpr BOOST_FIT_SFINAE_MANUAL_RESULT(const v_fold&, id_, result_of, id_>, id_...) + operator()(const F& f, State&& state, T&& x, Ts&&... xs) const BOOST_FIT_SFINAE_MANUAL_RETURNS ( - (*FIT_CONST_THIS)(f, f(FIT_FORWARD(State)(state), FIT_FORWARD(T)(x)), FIT_FORWARD(Ts)(xs)...) + (*BOOST_FIT_CONST_THIS)(f, f(BOOST_FIT_FORWARD(State)(state), BOOST_FIT_FORWARD(T)(x)), BOOST_FIT_FORWARD(Ts)(xs)...) ); template constexpr State operator()(const F&, State&& state) const { - return FIT_FORWARD(State)(state); + return BOOST_FIT_FORWARD(State)(state); } }; @@ -99,7 +99,7 @@ struct compress_adaptor : detail::compressed_pair, State> { typedef detail::compressed_pair, State> base_type; - FIT_INHERIT_CONSTRUCTOR(compress_adaptor, base_type) + BOOST_FIT_INHERIT_CONSTRUCTOR(compress_adaptor, base_type) template constexpr const detail::callable_base& base_function(Ts&&... xs) const @@ -114,13 +114,13 @@ struct compress_adaptor } template - constexpr FIT_SFINAE_RESULT(detail::v_fold, id_&>, id_, id_...) - operator()(Ts&&... xs) const FIT_SFINAE_RETURNS + constexpr BOOST_FIT_SFINAE_RESULT(detail::v_fold, id_&>, id_, id_...) + operator()(Ts&&... xs) const BOOST_FIT_SFINAE_RETURNS ( detail::v_fold()( - FIT_MANGLE_CAST(const detail::callable_base&)(this->base_function(xs...)), - FIT_MANGLE_CAST(State)(this->get_state(xs...)), - FIT_FORWARD(Ts)(xs)... + BOOST_FIT_MANGLE_CAST(const detail::callable_base&)(this->base_function(xs...)), + BOOST_FIT_MANGLE_CAST(State)(this->get_state(xs...)), + BOOST_FIT_FORWARD(Ts)(xs)... ) ) }; @@ -130,7 +130,7 @@ template struct compress_adaptor : detail::callable_base { - FIT_INHERIT_CONSTRUCTOR(compress_adaptor, detail::callable_base) + BOOST_FIT_INHERIT_CONSTRUCTOR(compress_adaptor, detail::callable_base) template constexpr const detail::callable_base& base_function(Ts&&... xs) const @@ -139,18 +139,18 @@ struct compress_adaptor } template - constexpr FIT_SFINAE_RESULT(detail::v_fold, id_&>, id_...) - operator()(Ts&&... xs) const FIT_SFINAE_RETURNS + constexpr BOOST_FIT_SFINAE_RESULT(detail::v_fold, id_&>, id_...) + operator()(Ts&&... xs) const BOOST_FIT_SFINAE_RETURNS ( detail::v_fold()( - FIT_MANGLE_CAST(const detail::callable_base&)(this->base_function(xs...)), - FIT_FORWARD(Ts)(xs)... + BOOST_FIT_MANGLE_CAST(const detail::callable_base&)(this->base_function(xs...)), + BOOST_FIT_FORWARD(Ts)(xs)... ) ) }; -FIT_DECLARE_STATIC_VAR(compress, detail::make); +BOOST_FIT_DECLARE_STATIC_VAR(compress, detail::make); -} // namespace fit +}} // namespace boost::fit #endif diff --git a/include/fit/conditional.hpp b/include/boost/fit/conditional.hpp similarity index 65% rename from include/fit/conditional.hpp rename to include/boost/fit/conditional.hpp index b05f68e..e1b112a 100644 --- a/include/fit/conditional.hpp +++ b/include/boost/fit/conditional.hpp @@ -5,8 +5,8 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ -#ifndef FIT_GUARD_FUNCTION_CONDITIONAL_H -#define FIT_GUARD_FUNCTION_CONDITIONAL_H +#ifndef BOOST_FIT_GUARD_FUNCTION_CONDITIONAL_H +#define BOOST_FIT_GUARD_FUNCTION_CONDITIONAL_H /// conditional /// =========== @@ -67,35 +67,35 @@ /// So, the order of the functions in the `conditional_adaptor` are very important /// to how the function is chosen. -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include -namespace fit { +namespace boost { namespace fit { namespace detail { template struct conditional_kernel : F1, F2 { - FIT_INHERIT_DEFAULT(conditional_kernel, F1, F2) + BOOST_FIT_INHERIT_DEFAULT(conditional_kernel, F1, F2) template - constexpr conditional_kernel(A&& f1, B&& f2) : F1(FIT_FORWARD(A)(f1)), F2(FIT_FORWARD(B)(f2)) + BOOST_FIT_ENABLE_IF_CONVERTIBLE(A, F1), + BOOST_FIT_ENABLE_IF_CONVERTIBLE(B, F2)> + constexpr conditional_kernel(A&& f1, B&& f2) : F1(BOOST_FIT_FORWARD(A)(f1)), F2(BOOST_FIT_FORWARD(B)(f2)) {} template::type> - constexpr conditional_kernel(X&& x) : F1(FIT_FORWARD(X)(x)) + constexpr conditional_kernel(X&& x) : F1(BOOST_FIT_FORWARD(X)(x)) {} template @@ -108,39 +108,39 @@ struct conditional_kernel : F1, F2 > {}; - FIT_RETURNS_CLASS(conditional_kernel); + BOOST_FIT_RETURNS_CLASS(conditional_kernel); template::type> - constexpr FIT_SFINAE_RESULT(typename select::type, id_...) + constexpr BOOST_FIT_SFINAE_RESULT(typename select::type, id_...) operator()(Ts && ... x) const - FIT_SFINAE_RETURNS + BOOST_FIT_SFINAE_RETURNS ( - FIT_RETURNS_STATIC_CAST(const F&)(*FIT_CONST_THIS)(FIT_FORWARD(Ts)(x)...) + BOOST_FIT_RETURNS_STATIC_CAST(const F&)(*BOOST_FIT_CONST_THIS)(BOOST_FIT_FORWARD(Ts)(x)...) ); }; } template struct conditional_adaptor -: detail::conditional_kernel +: detail::conditional_kernel { typedef conditional_adaptor fit_rewritable_tag; - typedef FIT_JOIN(conditional_adaptor, Fs...) kernel_base; + typedef BOOST_FIT_JOIN(conditional_adaptor, Fs...) kernel_base; typedef detail::conditional_kernel base; - FIT_INHERIT_DEFAULT(conditional_adaptor, base) + BOOST_FIT_INHERIT_DEFAULT(conditional_adaptor, base) template + BOOST_FIT_ENABLE_IF_CONSTRUCTIBLE(base, X, kernel_base), + BOOST_FIT_ENABLE_IF_CONSTRUCTIBLE(kernel_base, Xs...)> constexpr conditional_adaptor(X&& f1, Xs&& ... fs) - : base(FIT_FORWARD(X)(f1), kernel_base(FIT_FORWARD(Xs)(fs)...)) + : base(BOOST_FIT_FORWARD(X)(f1), kernel_base(BOOST_FIT_FORWARD(Xs)(fs)...)) {} template + BOOST_FIT_ENABLE_IF_CONSTRUCTIBLE(base, X)> constexpr conditional_adaptor(X&& f1) - : base(FIT_FORWARD(X)(f1)) + : base(BOOST_FIT_FORWARD(X)(f1)) {} struct failure @@ -152,7 +152,7 @@ template struct conditional_adaptor : F { typedef conditional_adaptor fit_rewritable_tag; - FIT_INHERIT_CONSTRUCTOR(conditional_adaptor, F); + BOOST_FIT_INHERIT_CONSTRUCTOR(conditional_adaptor, F); struct failure : failure_for @@ -165,15 +165,15 @@ struct conditional_adaptor { typedef detail::conditional_kernel base; typedef conditional_adaptor fit_rewritable_tag; - FIT_INHERIT_CONSTRUCTOR(conditional_adaptor, base); + BOOST_FIT_INHERIT_CONSTRUCTOR(conditional_adaptor, base); struct failure : failure_for {}; }; -FIT_DECLARE_STATIC_VAR(conditional, detail::make); +BOOST_FIT_DECLARE_STATIC_VAR(conditional, detail::make); -} // namespace fit +}} // namespace boost::fit #endif diff --git a/include/fit/construct.hpp b/include/boost/fit/construct.hpp similarity index 78% rename from include/fit/construct.hpp rename to include/boost/fit/construct.hpp index ae473d5..979475f 100644 --- a/include/fit/construct.hpp +++ b/include/boost/fit/construct.hpp @@ -5,8 +5,8 @@ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ -#ifndef FIT_GUARD_CONSTRUCT_H -#define FIT_GUARD_CONSTRUCT_H +#ifndef BOOST_FIT_GUARD_CONSTRUCT_H +#define BOOST_FIT_GUARD_CONSTRUCT_H /// construct /// ========= @@ -61,18 +61,18 @@ /// Example /// ------- /// -/// auto v = fit::construct>()(5, 5); +/// auto v = boost::fit::construct>()(5, 5); /// assert(v.size() == 5); /// -#include -#include -#include -#include +#include +#include +#include +#include #include -namespace fit { +namespace boost { namespace fit { template struct by_adaptor; @@ -84,25 +84,25 @@ struct construct_f { constexpr construct_f() {} - template + template constexpr T operator()(Ts&&... xs) const { - return T(FIT_FORWARD(Ts)(xs)...); + return T(BOOST_FIT_FORWARD(Ts)(xs)...); } - template&&)> + template&&)> constexpr T operator()(std::initializer_list&& x) const { return T(static_cast&&>(x)); } - template&)> + template&)> constexpr T operator()(std::initializer_list& x) const { return T(x); } - template&)> + template&)> constexpr T operator()(const std::initializer_list& x) const { return T(x); @@ -120,11 +120,11 @@ struct construct_template_f { constexpr construct_template_f() {} - template + template constexpr Result operator()(Ts&&... xs) const { - return Result(FIT_FORWARD(Ts)(xs)...); + return Result(BOOST_FIT_FORWARD(Ts)(xs)...); } template @@ -146,12 +146,12 @@ struct construct_meta_f {}; template + BOOST_FIT_ENABLE_IF_CONSTRUCTIBLE(Result, Ts...)> constexpr Result operator()(Ts&&... xs) const { - return Result(FIT_FORWARD(Ts)(xs)...); + return Result(BOOST_FIT_FORWARD(Ts)(xs)...); } template @@ -167,12 +167,12 @@ struct construct_meta_template_f constexpr construct_meta_template_f() {} template + BOOST_FIT_ENABLE_IF_CONSTRUCTIBLE(Result, Ts...)> constexpr Result operator()(Ts&&... xs) const { - return Result(FIT_FORWARD(Ts)(xs)...); + return Result(BOOST_FIT_FORWARD(Ts)(xs)...); } template @@ -211,6 +211,6 @@ constexpr detail::construct_meta_template_f