### Boost Phoenix Execution Setup Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/lazy_list/tutorial_with_examples Sets up the execution environment for Boost Phoenix code by declaring argument names and bringing core Phoenix components into the current namespace. This allows for concise expression writing. ```cpp using boost::phoenix::arg_names::arg1; using boost::phoenix::arg_names::arg2; using namespace boost::phoenix; ``` -------------------------------- ### Boost Phoenix Header Inclusion Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/lazy_list/tutorial_with_examples Includes the necessary Boost Phoenix header file for utilizing lazy prelude functions. This is a foundational step for most Boost Phoenix examples. ```cpp #include ``` -------------------------------- ### Enum_from Function Call Example (C++) Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/lazy_list/implementation_details This snippet shows a conceptual example of how the enum_from function might be called, taking an integer argument to start the list generation. ```C++ enum_from(1) ``` -------------------------------- ### Boost Phoenix switch_ Statement Example Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/statement/switch__statement An example demonstrating the usage of the Boost Phoenix switch_ statement to print different messages based on the value of an element. ```c++ std::for_each(c.begin(), c.end(), switch_(arg1) [ case_<1>(std::cout << val("one") << '\n'), case_<2>(std::cout << val("two") << '\n'), default_(std::cout << val("other value") << '\n') ] ); ``` -------------------------------- ### Basic Phoenix Expression Example Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/inside/actions Illustrates a simple arithmetic expression within a Phoenix expression tree, showing how it's evaluated top-down. ```phoenix _1 + 3 * _2 ``` -------------------------------- ### Boost Phoenix do_while_ Statement Example Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/statement/___do_while_____statement Provides a C++ example of using the do_while_ statement in Boost Phoenix to iterate and print elements from a container, with a slight modification in logic compared to a previous example. ```cpp std::for_each(c.begin(), c.end(), ( do_ [ cout << arg1 << ", " ] .while_(arg1--), cout << val("\n") ) ); ``` -------------------------------- ### Evaluating a Reference in Boost Phoenix Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/core/references Shows how to evaluate a Boost Phoenix reference to get the value it refers to. The example demonstrates evaluating references to an integer and a C-style string. ```cpp int i = 3; char const* s = "Hello World"; cout << ref(i)() << ref(s)(); ``` -------------------------------- ### Phoenix Lazy Evaluation: Full Evaluation Example Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/basics Illustrates the complete evaluation of a Phoenix expression, showing both the partial application and the subsequent invocation with arguments. This example demonstrates checking if a number is odd using 'arg1'. ```c++ int x = 1; int y = 2; std::cout << (arg1 % 2 == 1)(x) << std::endl; // prints 1 or true std::cout << (arg1 % 2 == 1)(y) << std::endl; // prints 0 or false ``` -------------------------------- ### Lazy Operator Evaluation Examples Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/operator Demonstrates various syntaxes for lazily evaluating operators using Boost Phoenix, including infix, prefix, and postfix. ```cpp arg1 + arg2 1 + arg1 * arg2 1 / -arg1 arg1 < 150 ``` -------------------------------- ### Actor Evaluation Example Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/inside/actor Provides an example of an `actor::operator()` that utilizes the `evaluator`. ```APIDOC ## Actor Evaluation Example ### Description This example shows how an `actor`'s function call operator builds a context and invokes the evaluator. ### Method N/A (Method Implementation) ### Endpoint N/A (Method Implementation) ### Parameters N/A (Method Implementation) ### Request Example N/A (Method Implementation) ### Response N/A (Method Implementation) ```cpp template typename result_of::actor::type operator()(T0 &t0, T1 &t1) const { fusion::vector2 env(t0, t1); return eval(*this, context(env, default_actions())); } ``` ``` -------------------------------- ### Boost Phoenix Arguments: arg1, arg2, arg3 Examples Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/starter_kit/arguments Demonstrates the usage of predefined arguments like arg1, arg2, and arg3 in Boost Phoenix. These arguments are functions that return the first, second, or third argument passed to them, respectively. ```c++ arg1 // one-or-more argument function that returns its first argument arg2 // two-or-more argument function that returns its second argument arg3 // three-or-more argument function that returns its third argument ``` ```c++ int i = 3; char const* s = "Hello World"; std::cout << arg1(i) << std::endl; // prints 3 std::cout << arg2(i, s) << std::endl; // prints "Hello World" ``` -------------------------------- ### Example of Lazy String Construction Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/object/new Illustrates how to lazily create a std::string object on the heap using two arguments for its constructor. ```cpp new_(arg1, arg2) ``` -------------------------------- ### Boost Phoenix Try Catch Statement Example Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/statement/try__catch__statement Provides a practical C++ example of the Boost Phoenix try_catch_ statement. This code snippet illustrates how to catch specific exceptions like runtime_error and general exceptions, printing relevant messages. ```cpp try_ [ f(arg1) ] .catch_() [ cout << val("caught runtime error or derived\n") ] .catch_(e_) [ cout << val("caught exception or derived: ") << bind(&exception::what, e_) << val("\n") ] .catch_all [ cout << val("caught some other type of exception\n") ] ``` -------------------------------- ### Boost.Phoenix if_else_ Example: Conditional Output Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/statement/___if_else_____statement An example demonstrating the usage of the Boost.Phoenix if_else_ statement with nested conditions to print output based on the value of elements in a container. ```c++ std::for_each(c.begin(), c.end(), if_(arg1 > 5) [ cout << arg1 << " > 5\n" ] .else_ [ if_(arg1 == 5) [ cout << arg1 << " == 5\n" ] .else_ [ cout << arg1 << " < 5\n" ] ] ); ``` -------------------------------- ### Boost.Phoenix Lazy Expression Examples Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/starter_kit/lazy_operators Demonstrates various ways to form expressions using Boost.Phoenix operators, including arithmetic, assignment, and indexing. Illustrates the shorthand for 'val' and the rules for its use in binary and unary expressions. ```c++ arg1 * arg1 ref(x) = arg1 + ref(z) arg1 = arg2 + (3 * arg3) ref(x) = arg1[arg2] // assuming arg1 is indexable and arg2 is a valid index ``` ```c++ ref(x) = 123 // lazy x = 123 // immediate ref(x)[0] // lazy x[0] // immediate ref(x)[ref(i)] // lazy ref(x)[i] // lazy (equivalent to ref(x)[val(i)]) x[ref(i)] // illegal (x is not a phoenix primitive or expression) ref(x[ref(i)]) // illegal (x is not a phoenix primitive or expression) ``` -------------------------------- ### Example of potentially runaway operation Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/lazy_list/exceptions Illustrates a scenario that could lead to a runaway operation, specifically taking the length of an infinitely generated list. This is a key example demonstrating the need for exception handling. ```cpp length(enum_from(1)) ``` -------------------------------- ### Phoenix Lazy Evaluation: Partial Application Example Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/basics Demonstrates the first stage of Phoenix evaluation: partial application, where a generator function creates a higher-order function. This code snippet shows a simple modulo operation as an example. ```c++ arg1 % 2 == 1 ``` -------------------------------- ### STL Container Member Function Examples (C++) Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/stl/container Demonstrates the difference between normal and lazy versions of STL container member functions using Boost Phoenix. The lazy versions are free functions that take the container as the first argument. ```cpp // Normal version: my_vector.at(5); // Lazy version: at(arg1, 5); // Normal version: my_list.size(); // Lazy version: size(arg1); // Normal version: my_vector1.swap(my_vector2); // Lazy version: swap(arg1, arg2); ``` -------------------------------- ### Boost Phoenix for_ Statement Example Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/statement/for_statement An example demonstrating the Boost.Phoenix for_ statement's usage with std::for_each. It iterates through a container, printing each element N times, where N is the element's value. This utilizes lazy evaluation and reference actors. ```cpp int iii; std::for_each(c.begin(), c.end(), ( for_(ref(iii) = 0, ref(iii) < arg1, ++ref(iii)) [ cout << arg1 << ", " ], cout << val("\n") ) ); ``` -------------------------------- ### Evaluating Boost Phoenix Values Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/core/values Illustrates how to evaluate Boost Phoenix values by invoking them, which returns the value's identity. This example prints integer and string values. ```cpp cout << val(3)() << val("Hello World")(); // Output: 3 Hello World ``` -------------------------------- ### Creating Nullary Functions with val() in C++ Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/starter_kit/values Demonstrates how the `val()` function in Boost Phoenix creates nullary functions that return specified values. It shows examples of returning an integer and a C-style string. ```cpp val(3) val("Hello, World") ``` -------------------------------- ### Standard vs. Phoenix STL Copy Algorithm Example Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/stl/algorithm Demonstrates the difference between using the standard std::copy algorithm which requires explicit iterators, and the Boost.Phoenix copy algorithm which automatically deduces the end iterator. ```c++ int array[] = {1, 2, 3}; int output[3]; std::copy(array, array + 3, output); // Standard C++ requires explicit iterators ``` ```c++ int array[] = {1, 2, 3}; int output[3]; copy(arg1, arg2)(array, output); // Phoenix automatically deduces the end iterator ``` -------------------------------- ### Phoenix Polymorphic Function: String Concatenation Example Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/basics Demonstrates the polymorphic nature of Phoenix functions using the 'add' example. This snippet shows how 'add' can concatenate a std::string and a C-style string, highlighting heterogeneous argument handling. ```c++ std::string h("Hello"); char const* w = " World"; std::string r = add(arg1, arg2)(h, w); // evaluates to std::string("Hello World") ``` -------------------------------- ### Examples of Inverted Expressions Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/examples/transforming_the_expression_tree This snippet showcases various Boost.Phoenix expressions and their expected output after being processed by the 'invert' function, which applies the defined operator transformations (plus to minus, minus to plus, etc.). It illustrates the practical application of the custom actions. ```cpp invert(_1); // --> _1 invert(_1 + _2); // --> _1 - _2 invert(_1 + _2 - _3); // --> _1 - _2 + _3 invert(_1 * _2); // --> _1 / _2 invert(_1 * _2 / _3); // --> _1 / _2 * _3 invert(_1 * _2 + _3); // --> _1 / _2 - _3 invert(_1 * _2 - _3); // --> _1 / _2 + _2 invert(if_(_1 * _4)[_2 - _3]); // --> if_(_1 / _4)[_2 + _3] _1 * invert(_2 - _3)); // --> _1 * _2 + _3 ``` -------------------------------- ### Handle boost::reference_wrapper as Custom Terminal in Boost Phoenix Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/inside/custom_terminals This example demonstrates the special handling of `boost::reference_wrapper` within Boost Phoenix. It specializes `is_custom_terminal` and `custom_terminal` to enable Phoenix to use reference semantics transparently. ```cpp // Call out boost::reference_wrapper for special handling template struct is_custom_terminal > : mpl::true_ {}; // Special handling for boost::reference_wrapper template struct custom_terminal > { typedef T &result_type; template T &operator()(boost::reference_wrapper r, Context &) const { return r; } }; ``` -------------------------------- ### Generate Infinite Integer List (Boost.Phoenix) Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/lazy_list/tutorial_with_examples/list_generation Generates an infinite lazy list of integers starting from a given number. This function is fundamental for creating sequences that are evaluated on demand. ```phoenix enum_from(1) ``` -------------------------------- ### Adapt C++ Callable 'plus' for 2 and 3 Arguments with Boost.Phoenix Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/function/adapting_functions This C++ code defines a structure 'demo::plus' that overloads the operator() to perform addition for two or three arguments. It then uses Boost.Phoenix macros (BOOST_PHOENIX_ADAPT_CALLABLE) to make these operations callable within the Phoenix functional programming framework. The example in 'main' demonstrates how to use the adapted 'plus' function with placeholders like 'arg1' and 'arg2'. ```C++ namespace demo { struct plus { template struct result; template struct result : remove_reference {}; template struct result : remove_reference {}; template A0 operator()(A0 const & a0, A1 const & a1) const { return a0 + a1; } template A0 operator()(A0 const & a0, A1 const & a1, A2 const & a2) const { return a0 + a1 + a2; } }; } BOOST_PHOENIX_ADAPT_CALLABLE(plus, demo::plus, 2) BOOST_PHOENIX_ADAPT_CALLABLE(plus, demo::plus, 3) int main() { using boost::phoenix::arg_names::arg1; using boost::phoenix::arg_names::arg2; int a = 123; int b = 256; assert(plus(arg1, arg2)(a, b) == a+b); assert(plus(arg1, arg2, 3)(a, b) == a+b+3); } ``` -------------------------------- ### Boost C++ Block Statement with Parentheses Grouping Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/statement/block_statement Provides an example of using Boost C++ block statements grouped with parentheses within a standard library function like `std::for_each`. This demonstrates practical application of the syntax. ```c++ std::for_each(c.begin(), c.end(), ( do_this(arg1), do_that(arg1) ) ); ``` -------------------------------- ### Regular Functions for Context Management Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/inside/actions Shows regular C++ functions provided by Boost.Phoenix for creating and accessing context, environment, and actions. ```cpp context(env, actions) ``` ```cpp env(ctx) ``` ```cpp actions(ctx) ``` -------------------------------- ### Primitive Transforms for Context Access Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/inside/actions Lists predefined primitive transforms in Boost.Phoenix for accessing the current context, environment, and actions. ```phoenix _context ``` ```phoenix _env ``` ```phoenix _actions ``` -------------------------------- ### Include Boost Phoenix Reference Header Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/core/references Includes the necessary header file for Boost Phoenix's reference functionality. ```cpp #include ``` -------------------------------- ### Example: Static Cast in Boost Phoenix Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/object/casts An example showing how to use the static_cast_ function in Boost Phoenix to cast the address of a variable to a pointer of a base type. ```cpp static_cast_(&arg1) ``` -------------------------------- ### Include Boost Phoenix Object Construction Header Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/object/construction This code snippet includes the necessary header file for using Boost.Phoenix's object construction features. ```c++ #include ``` -------------------------------- ### Boost Phoenix: Basic Arithmetic Operations Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/lazy_list/tutorial_with_examples/arithmetic_functions Demonstrates the fundamental usage of Boost Phoenix's arithmetic functions like 'plus', 'minus', 'multiplies', 'divides', 'modulus', 'min', and 'max'. It shows how to define expressions using placeholders and apply them to integer arguments. ```cpp int a = 123; int b = 256; // plus(arg1, arg2)(a, b) // plus(arg1, b)(a) // plus(a, arg2)(a,b) // plus(a, arg1)(b) // plus(a, b)() // plus(minus(arg1, arg2),b)(a,b) // plus(minus(arg1, arg2),arg2)(a,b) // multiplies(arg1,arg2)(3,6) // divides(arg2,arg1)(3,6) // modulus(arg2,arg1)(4,6) // min(arg1,arg2)(4,6) // max(arg1,arg2)(4,6) // inc(arg1)(a) // dec(arg1)(a) // negate(arg1)(a) ``` -------------------------------- ### Declare Integer and String Variables (C++) Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/starter_kit/references Declares an integer variable 'i' initialized to 3 and a constant character pointer 's' initialized to 'Hello World'. These are foundational for demonstrating reference creation. ```cpp int i = 3; char const* s = "Hello World"; ``` -------------------------------- ### Functional Transforms for Context Manipulation Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/inside/actions Lists predefined functional transforms in Boost.Phoenix for interacting with context, environment, and actions. ```phoenix functional::context(Env, Actions) ``` ```phoenix functional::env(Context) ``` ```phoenix functional::actions(Context) ``` -------------------------------- ### Include Boost.Phoenix STL Algorithm Headers Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/stl/algorithm Includes necessary headers for using Boost.Phoenix wrappers for STL algorithms, categorizing them into iteration, transformation, and querying. ```c++ #include ``` ```c++ #include ``` ```c++ #include ``` ```c++ #include ``` -------------------------------- ### Include Boost Phoenix Bind Function Header Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/bind/binding_functions Includes the necessary header file for using Boost.Phoenix binding functions. This is the primary step to enable function binding capabilities. ```cpp #include ``` -------------------------------- ### Boost Phoenix while_ Statement Example: Decrement and Print Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/statement/while__statement An example showing how to use the Boost Phoenix while_ statement to decrement elements in a container until they reach zero, printing each value along the way. It utilizes std::for_each and Phoenix expressions. ```cpp std::for_each(c.begin(), c.end(), ( while_(arg1--) [ cout << arg1 << ", " ], cout << val("\n") ) ); ``` -------------------------------- ### Lazy Operator Execution Example Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/operator Illustrates how a lazily evaluated expression is invoked and its result is printed to standard output. ```cpp std::cout << ((arg1 + arg2) * arg3)(4, 5, 6); ``` -------------------------------- ### Boost.Phoenix Evaluator Definition and Usage Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/inside/actor Defines the `evaluator` struct, which is used to start the evaluation of a Phoenix expression by calling its function call operator. An instance `eval` is provided for convenience. ```cpp struct evaluator { template _unspecified_ operator()(Expr &, Context &); }; evaluator const eval = {}; ``` -------------------------------- ### Include Boost.Phoenix Tuple Header Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/stl/tuple Includes the necessary header file for the Boost.Phoenix Tuple library functionality. ```cpp #include ``` -------------------------------- ### Assigning Value to Bound Member Variable Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/bind/binding_member_variables Illustrates how to assign a value to a bound member variable. The example shows assigning `4` to `obj.v` through a lazy binding. ```cpp bind(&xyz::v, arg1)(obj) = 4 // obj.v = 4 ``` -------------------------------- ### Phoenix: expression::complement and rule::complement Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/inside/rules Shows the expression for bitwise complement and its corresponding rule definition in Boost.Phoenix, using meta_grammar for the operand. ```cpp rule::complement : expression::complement ``` -------------------------------- ### Phoenix STL Algorithm Overview Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/stl/algorithm The Phoenix algorithm module offers wrappers for standard algorithms, categorized into iteration, transformation, and querying. These wrappers often simplify usage by automatically handling range end iterators. ```APIDOC ## Phoenix STL Algorithms ### Description The Phoenix library provides wrappers for standard C++ algorithms found in `` and `` headers. These wrappers simplify the use of these algorithms within the Phoenix functional programming context, often by automatically deducing range boundaries. ### Usage Example ```cpp #include #include int main() { int array[] = {1, 2, 3}; int output[3]; // Using std::copy requires explicit iterators for start and end // std::copy(array, array + 3, output); // Phoenix copy can infer the end iterator copy(arg1, arg2)(array, output); return 0; } ``` ### Algorithm Categories **1. Iteration Algorithms:** - `for_each(r, f)`: Applies a function `f` to each element in range `r`. - `accumulate(r, o[, f])`: Accumulates values in range `r` starting with initial value `o`, optionally using function `f`. **2. Querying Algorithms:** - `find(r, a)`: Finds the first element in range `r` equal to `a`. - `find_if(r, f)`: Finds the first element in range `r` for which predicate `f` returns true. - `find_end(r1, r2[, f])`: Finds the last sub-sequence in `r1` that matches `r2`. - `find_first_of(r1, r2[, f])`: Finds the first element in `r1` that matches any element in `r2`. - `adjacent_find(r[, f])`: Finds the first pair of adjacent elements in `r` that are equal or satisfy predicate `f`. - `count(r, a)`: Counts the occurrences of `a` in range `r`. - `count_if(r, f)`: Counts elements in range `r` for which predicate `f` returns true. - `distance(r)`: Computes the distance between the beginning and end of range `r`. - `mismatch(r, i[, f])`: Finds the first pair of elements in `r` and `i` that do not match. - `equal(r, i[, f])`: Checks if range `r` is equal to another sequence starting at `i`. - `search(r1, r2[, f])`: Searches for the first occurrence of sub-sequence `r2` within `r1`. - `lower_bound(r, a[, f])`: Finds the lower bound for `a` in the sorted range `r`. - `upper_bound(r, a[, f])`: Finds the upper bound for `a` in the sorted range `r`. - `equal_range(r, a[, f])`: Returns the range of elements equal to `a` in the sorted range `r`. - `binary_search(r, a[, f])`: Checks if `a` is present in the sorted range `r`. - `includes(r1, r2[, f])`: Checks if the sorted range `r1` contains all elements of the sorted range `r2`. - `min_element(r[, f])`: Finds the iterator to the smallest element in range `r`. - `max_element(r[, f])`: Finds the iterator to the largest element in range `r`. - `lexicographical_compare(r1, r2[, f])`: Compares two ranges lexicographically. **3. Transformation Algorithms:** - `copy(r, o)`: Copies elements from range `r` to output `o`. - `copy_backward(r, o)`: Copies elements from range `r` to output `o` in reverse order. - `transform(r, o, f)`: Applies function `f` to elements in `r` and stores results in `o`. - `transform(r, i, o, f)`: Applies binary function `f` to elements from `r` and `i`, storing results in `o`. - `replace(r, a, b)`: Replaces all occurrences of `a` with `b` in range `r`. - `replace_if(r, f, a)`: Replaces elements in `r` for which `f` is true with `a`. - `replace_copy(r, o, a, b)`: Copies range `r` to `o`, replacing `a` with `b`. - `replace_copy_if(r, o, f, a)`: Copies range `r` to `o`, replacing elements where `f` is true with `a`. - `fill(r, a)`: Assigns value `a` to all elements in range `r`. - `fill_n(r, n, a)`: Assigns value `a` to the first `n` elements in range `r`. - `generate(r, f)`: Assigns the result of calling function `f` to each element in range `r`. - `generate_n(r, n, f)`: Assigns the result of calling `f` to the first `n` elements in range `r`. - `remove(r, a)`: Removes elements equal to `a` from range `r` (by shifting subsequent elements). - `remove_if(r, f)`: Removes elements from range `r` for which `f` is true. - `remove_copy(r, o, a)`: Copies range `r` to `o`, omitting elements equal to `a`. - `remove_copy_if(r, o, f)`: Copies range `r` to `o`, omitting elements for which `f` is true. - `unique(r[, f])`: Removes consecutive duplicate elements in range `r`. - `unique_copy(r, o[, f])`: Copies range `r` to `o`, removing consecutive duplicates. - `reverse(r)`: Reverses the order of elements in range `r`. - `reverse_copy(r, o)`: Copies range `r` to `o` in reverse order. - `rotate(r, m)`: Rotates the elements in range `r` such that element at `m` becomes the new first element. - `rotate_copy(r, m, o)`: Copies range `r` to `o` after rotating it. - `random_shuffle(r[, f])`: Randomly shuffles elements in range `r`. - `partition(r, f)`: Rearranges elements in `r` such that elements satisfying `f` come before those that don't. - `stable_partition(r, f)`: Rearranges elements in `r` such that elements satisfying `f` come before those that don't, preserving relative order. - `sort(r[, f])`: Sorts the elements in range `r`. - `stable_sort(r[, f])`: Sorts the elements in range `r`, preserving the relative order of equal elements. ``` -------------------------------- ### Boost Phoenix Lambda Syntax and Usage Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/scope/lambda Demonstrates the basic syntax of Boost Phoenix lambdas and their use in creating lazy functions, particularly with higher-order functions. It shows how lambdas capture arguments and manage scope for deferred execution. ```cpp #include struct for_each_impl { template struct result { typedef void type; }; template void operator()(C& c, F f) const { std::for_each(c.begin(), c.end(), f); } }; function const for_each = for_each_impl(); // Simple syntax: // lambda [ // lambda-body // ] // With local declarations: // lambda(local-declarations) // [ // lambda-body // ] // Example using lazy for_each to print elements: // for_each(arg1, lambda[cout << arg1]) ``` -------------------------------- ### Implement 'id' function with Boost Phoenix Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/lazy_list/implementation_details Implements a simple 'id' function that returns its argument using Boost Phoenix. This example demonstrates the structure for defining custom functions within the 'impl' namespace. ```cpp namespace impl { struct Id { template struct result; template struct result : boost::remove_reference {}; template A0 operator()(A0 const & a0) const { return a0; } }; } typedef boost::phoenix::function Id; Id id; ``` -------------------------------- ### Boost Phoenix do_while_ Statement Syntax Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/statement/___do_while_____statement Demonstrates the syntax for the do_while_ statement in Boost Phoenix, including the required include directive and the structure of the statement. ```cpp #include ``` ```cpp do_ [ sequenced_statements ] .while_(conditional_expression) ``` -------------------------------- ### Using ref() to Create a Mutable Reference Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/core/references Demonstrates how to use the `ref()` function to create a mutable reference to a variable, allowing it to be modified by a function like `add_assign`. This is a pseudo-code example illustrating the concept. ```cpp void add_assign(T& x, T y) { x += y; } // pseudo code add_assign(ref(i), 2) ``` -------------------------------- ### Evaluate and Display Phoenix Expression (C++) Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/inside/expression Demonstrates how to evaluate a Phoenix expression by invoking it and how to display the expression's structure using proto::display_expr. ```cpp plus(6, 5)(); proto::display_expr(plus(5, 6)); ``` -------------------------------- ### Logical Predicates for Lazy Lists in Boost.Phoenix Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/lazy_list/what_is_provided Lists logical predicate functions in Boost.Phoenix that test properties of elements within a lazy list. Functions like 'odd' and 'even' are examples of these predicates. ```cpp // Logical predicates odd even ``` -------------------------------- ### Runtime evaluation of Boost.Phoenix 'while_' loop Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/examples/adding_an_expression Illustrates the runtime execution logic of the 'while_' loop as implemented in `while_eval`. It shows how the condition and action actors are evaluated within the loop's context. ```c++ while(eval(cond, ctx)) { eval(do_, ctx); } ``` -------------------------------- ### Include Boost Phoenix Value Header Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/core/values Includes the necessary header file for using Boost Phoenix values in C++. ```cpp #include ``` -------------------------------- ### Phoenix Expression Semantics (C++) Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/inside/expression Illustrates the semantics of Phoenix expressions, showing how to access the expression type, grammar, and create an expression instance using the make function. ```cpp Expression | Semantics --|-- `expr::type` | The type of Expression having tag `Tag` and `A0...AN` children `expr` | A Boost.Proto grammar and Proto Pass Through Transform `expr::make(a0...aN)` | Returns a Phoenix Expression ``` -------------------------------- ### Boost Phoenix: Conditional Output with if_ Statement Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/starter_kit/lazy_statements Shows a basic example of using the Boost Phoenix 'if_' lazy statement to conditionally execute an output statement. It checks if 'arg1' is greater than 5 and prints it if true. ```cpp if_(arg1 > 5) [ std::cout << arg1 ] ``` -------------------------------- ### Boost Phoenix Predefined Arguments (BLL _N) Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/core/arguments Declares and initializes BLL-style (Boost.Lambda Library) argument placeholders (_1, _2, _3) using `boost::phoenix::core::argument`. These provide an alternative syntax for referring to function arguments. ```c++ namespace placeholders { expression::argument<1>::type const _1 = {}; expression::argument<2>::type const _2 = {}; expression::argument<3>::type const _3 = {}; } ``` -------------------------------- ### Boost Phoenix function with one argument and defined return type Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/lazy_list/implementation_details Creates a Boost Phoenix function that takes one argument and has a defined return type using a templated struct. This example shows how to specify the return type for the function. ```cpp namespace impl { template struct what { typedef Result result_type; Result operator()(Result const & r) const { return r; } }; } boost::function1 what_int = impl::what(); typedef boost::function1 fun1_int_int; typedef boost::phoenix::function What_arg; What_arg what_arg(what_int); ``` -------------------------------- ### Include Boost Phoenix Object New Header Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/object/new This snippet shows the necessary include directive to use the lazy object construction features from Boost Phoenix. ```cpp #include ``` -------------------------------- ### Boost Phoenix Try Catch Statement Syntax Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/statement/try__catch__statement Demonstrates the general syntax for the Boost Phoenix try_catch_ statement. It outlines the structure for defining try blocks and various catch handlers for different exception types and a catch-all. ```cpp #include try_ [ sequenced_statements ] .catch_() [ sequenced_statements ] .catch_(local-id) [ sequenced_statements ] ... .catch_all [ sequenced_statement ] ``` -------------------------------- ### Lazy List Generation Functions in Boost.Phoenix Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/lazy_list/what_is_provided Describes functions used for generating lazy lists within the Boost.Phoenix library. Examples include creating sequences ('enum_from', 'enum_from_to') and lists with specified properties ('list_with'). ```cpp // List Generation Functions enum_from enum_from_to list_with ``` -------------------------------- ### Phoenix: Binary Arithmetic Operators (plus, minus, etc.) and corresponding rules Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/inside/rules Showcases Boost.Phoenix expressions for binary arithmetic operations (e.g., +, -) and their respective rule definitions using meta_grammar for both operands. ```cpp rule::plus : expression::plus ``` ```cpp rule::minus : expression::minus ``` ```cpp rule::multiplies : expression::multiplies ``` ```cpp rule::divides : expression::divides ``` ```cpp rule::modulus : expression::modulus ``` -------------------------------- ### Boost Phoenix function with zero arguments and defined return type Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/lazy_list/implementation_details Implements a Boost Phoenix function that takes zero arguments and has a defined return type. This example uses a templated struct to specify the return type and returns a default value. ```cpp namespace impl { template struct what0 { typedef Result result_type; Result operator()() const { return Result(100); } }; } typedef boost::function0 fun0_int; boost::function0 what0_int = impl::what0(); typedef boost::phoenix::function What0_arg; What0_arg what0_arg(what0_int); ``` -------------------------------- ### Boost Phoenix Evaluating Arguments Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/core/arguments Shows how argument placeholders like `arg1` and `arg2` are evaluated with client-provided data. When called with arguments, they select the specified argument from the input. ```c++ char c = 'A'; int i = 123; const char* s = "Hello World"; cout << arg1(c) << endl; // Get the 1st argument: c cout << arg1(i, s) << endl; // Get the 1st argument: i cout << arg2(i, s) << endl; // Get the 2nd argument: s ``` -------------------------------- ### Boost.Phoenix Actor Concept Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/inside/actor Details the requirements and semantics of the Actor concept in Boost.Phoenix. ```APIDOC ## Actor Concept Requirements ### Description The Actor concept defines the fundamental building block of Boost.Phoenix expressions, representing a callable entity that can evaluate a Phoenix expression. ### Method N/A (Concept Definition) ### Endpoint N/A (Concept Definition) ### Parameters N/A (Concept Definition) ### Request Example N/A (Concept Definition) ### Response N/A (Concept Definition) ## Table 1.9. Actor Concept Requirements Expression | Semantics ---|--- `actor(arg0, arg1, ..., argN)` | Function call operators to start the evaluation `boost::result_of(Arg0, Arg1, ..., ArgN)>::type` | Result of the evaluation `result_of::actor::type` | Result of the evaluation ``` -------------------------------- ### Invoke Lazy Function and Execute Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/function This C++ example shows how to invoke a lazy function created with Boost.Phoenix. The first call returns an actor, and a subsequent call executes the actual function logic, demonstrating deferred execution. ```cpp std::cout << factorial(arg1)(4); ``` -------------------------------- ### Enum_from Functor Implementation (C++) Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/lazy_list/implementation_details The Enum_from struct is a functor that initializes the list generation process. It takes an argument T and returns a delay result type, which is the result of calling the EFH functor. This is the entry point for generating sequences starting from a given number. ```C++ struct Enum_from { template struct result; template struct result { typedef typename boost::remove_reference::type TT; typedef typename boost::remove_const::type TTT; typedef typename UseList::template List::type LType; typedef typename result_of::ListType:: delay_result_type type; }; template typename result::type operator() (const T & x) const { typedef typename boost::remove_reference::type TT; typedef typename boost::remove_const::type TTT; typedef typename UseList::template List::type LType; typedef typename result_of::ListType:: delay_result_type result_type; typedef boost::function0 fun1_R_TTT; fun1_R_TTT efh_R_TTT = EFH(x); typedef boost::phoenix::function EFH_R_T; EFH_R_T efh_R_T(efh_R_TTT); //std::cout << "enum_from (" << x << ")" << std::endl; return efh_R_T(); } }; ``` -------------------------------- ### Reference preservation in Boost Phoenix `let` variable declaration Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/modules/scope/let Illustrates reference preservation when declaring local variables with `let`. `_a` assumes the type of `arg1` (a reference), while `_b` gets the type `int`. This is crucial for L-value access to outer lambda arguments. ```c++ int i = 1; let(_a = arg1) [ cout << --_a << ' ' ] (i); cout << i << endl; // Output: 0 0 let(_a = val(arg1)) [ cout << --_a << ' ' ] (i); cout << i << endl; // Output: 0 1 ``` -------------------------------- ### Actor Class Template Source: https://www.boost.org/doc/libs/1_89_0/libs/phoenix/doc/html/phoenix/inside/actor Illustrates the C++ template structure of the `actor` class. ```APIDOC ## Actor Class Template ### Description The `actor` template class is a C++ implementation that models the Actor concept. ### Method N/A (Class Definition) ### Endpoint N/A (Class Definition) ### Parameters N/A (Class Definition) ### Request Example N/A (Class Definition) ### Response N/A (Class Definition) ```cpp template struct actor { template struct result; typename result_of::actor::type operator()() const; template typename result_of::actor::type operator()(T0& _0) const; template typename result_of::actor::type operator()(T0 const & _0) const; //... }; ``` ```