|
SpECTRE
2021.08.02
|
A collection of useful classes, functions and metafunctions. More...
Namespaces | |
| namespace | alg |
| Utility functions wrapping STL algorithms and additional algorithms. | |
| namespace | formaline |
| Functions for retrieving system and source tree information. | |
| namespace | funcl |
Higher order function objects similar to std::plus, etc. | |
| namespace | gsl |
| Implementations from the Guideline Support Library. | |
| namespace | Registration |
| Helpers for derived class registration. | |
| namespace | tmpl2 |
| Metaprogramming things that are not planned to be submitted to Brigand. | |
Classes | |
| struct | GetContainerSize |
Callable struct which retrieves the t.size() for operand t. This will cause a compiler error if no such function exists. More... | |
| struct | GetContainerElement |
Callable struct for the subscript operator. Returns t[i] More... | |
| struct | ContainerDestructiveResize |
Callable struct which applies the t.destructive_resize() for operand t. This will cause a compiler error if no such function exists. More... | |
| class | ContinuedFraction< T > |
| Compute the continued fraction representation of a number. More... | |
| class | ContinuedFractionSummer< Fraction > |
| Sum a continued fraction. More... | |
| class | gsl::not_null< T > |
Require a pointer to not be a nullptr More... | |
| class | gsl::span< ElementType, Extent > |
| Create a span/view on a range, which is cheap to copy (one pointer). More... | |
| class | MakeString |
| Make a string by streaming into object. More... | |
| struct | NoSuchType |
| Used to mark "no type" or "bad state" for metaprogramming. More... | |
| class | Overloader< Fs > |
| Used for overloading lambdas, useful for lambda-SFINAE. More... | |
| class | Rational |
| A rational number. More... | |
| struct | CacheRange< Start, End > |
Range of integral values for StaticCache indices. The Start is inclusive and the End is exclusive. The range must not be empty. More... | |
| struct | CacheEnumeration< EnumerationType, Enums > |
| Possible enumeration values for the StaticCache. Only values specified here are retrievable. More... | |
| class | StaticCache< Generator, T, Ranges > |
| A cache of objects intended to be stored in a static variable. More... | |
| class | tuples::TaggedTuple< Tags > |
| An associative container that is indexed by structs. More... | |
| struct | tmpl2::value_list< T,... > |
| A compile-time list of values of the same type. More... | |
| struct | TypeDisplayer<... > |
| Get compiler error with type of template parameter. More... | |
| struct | make_list< Ts > |
| Metafunction to turn a parameter pack into a typelist. More... | |
Macros | |
| #define | DEFINE_FAKE_VIRTUAL(function) |
| Define a function that acts similarly to a virtual function, but can take template parameters. More... | |
| #define | SPECTRE_ALWAYS_INLINE inline |
| Always inline a function. Only use this if you benchmarked the code. | |
| #define | GENERATE_INSTANTIATIONS(INSTANTIATION_MACRO, ...) |
| Macro useful for generating many explicit instantiations of function or class templates. More... | |
| #define | LIKELY(x) (x) |
| #define | UNLIKELY(x) (x) |
| #define | DEFINE_STD_ARRAY_BINOP(RESULT_TYPE, LTYPE, RTYPE, OP_FUNCTION_NAME, BINARY_OP) |
Declares a binary function on an array, intended for binary operators such as + More... | |
| #define | DEFINE_STD_ARRAY_INPLACE_BINOP(LTYPE, RTYPE, OP_FUNCTION_NAME, BINARY_OP) |
Declares an in-place binary function on an array, intended for operations such as += More... | |
| #define | EXPAND_PACK_LEFT_TO_RIGHT(...) (void)std::initializer_list<char> { ((void)(__VA_ARGS__), '0')... } |
| Expand a parameter pack evaluating the terms from left to right. More... | |
Typedefs | |
| template<typename Sequence > | |
| using | make_boost_variant_over = typename detail::make_boost_variant_over_impl< tmpl::remove_duplicates< Sequence > >::type |
| Create a boost::variant with all all the types inside the typelist Sequence. More... | |
| template<class T , Requires< std::is_pointer< T >::value > = nullptr> | |
| using | gsl::owner = typename detail::owner_impl< T >::type |
| Mark a raw pointer as owning its data. More... | |
| template<bool B> | |
| using | Requires = typename Requires_detail::requires_impl< B >::template_error_type_failed_to_meet_requirements_on_template_parameters |
Express requirements on the template parameters of a function or class, replaces std::enable_if_t More... | |
| template<typename T > | |
| using | tuples::tagged_tuple_from_typelist = typename TaggedTuple_detail::tagged_tuple_typelist_impl< T >::type |
| template<bool... Bs> | |
| using | tmpl2::flat_all = std::is_same< value_list< bool, Bs... >, value_list< bool,(static_cast< void >(Bs), true)... > > |
| A non-short-circuiting logical AND between bools 'B"". More... | |
| template<bool... Bs> | |
| using | tmpl2::flat_any = std::integral_constant< bool, not std::is_same< value_list< bool, Bs... >, value_list< bool,(static_cast< void >(Bs), false)... > >::value > |
| A non-short-circuiting logical OR between bools 'B"". More... | |
| template<class Graph , class S , class D > | |
| using | brigand::has_edge = typename ::brigand::lazy::has_edge< Graph, S, D >::type |
Check if a digraph has an edge with source S and destination D | |
Functions | |
| template<class T > | |
| constexpr void | cpp20::swap (T &a, T &b) noexcept |
| template<class ForwardIt1 , class ForwardIt2 > | |
| constexpr void | cpp20::iter_swap (ForwardIt1 a, ForwardIt2 b) |
| template<class BidirectionalIterator > | |
| constexpr void | cpp20::reverse (BidirectionalIterator first, BidirectionalIterator last) |
| template<class Compare , class BidirectionalIterator > | |
| constexpr bool | cpp20::next_permutation (BidirectionalIterator first, BidirectionalIterator last, Compare comp) |
| template<class BidirectionalIterator > | |
| constexpr bool | cpp20::next_permutation (BidirectionalIterator first, BidirectionalIterator last) |
| template<class InputIt , class T > | |
| constexpr InputIt | cpp20::find (InputIt first, InputIt last, const T &value) |
| template<class InputIt , class UnaryPredicate > | |
| constexpr InputIt | cpp20::find_if (InputIt first, InputIt last, UnaryPredicate p) |
| template<class InputIt , class UnaryPredicate > | |
| constexpr InputIt | cpp20::find_if_not (InputIt first, InputIt last, UnaryPredicate q) |
| double | ddot_ (const size_t &N, const double *X, const size_t &INCX, const double *Y, const size_t &INCY) |
| template<typename... Ts> | |
| std::string | type_of_current_state (const boost::variant< Ts... > &variant) noexcept |
| Get the type name of the current state of the boost::variant. | |
| template<typename KeyType , typename T > | |
| std::unordered_map< KeyType, std::unique_ptr< T > > | clone_unique_ptrs (const std::unordered_map< KeyType, std::unique_ptr< T > > &map) noexcept |
Given a map of std::unique_ptr returns a copy of the map by invoking get_clone() on each element of the input map. | |
| template<typename T > | |
| std::vector< std::unique_ptr< T > > | clone_unique_ptrs (const std::vector< std::unique_ptr< T > > &vector) noexcept |
Given a vector of std::unique_ptr returns a copy of the vector by invoking get_clone() on each element of the input vector. | |
| template<typename T , typename SubscriptFunction = GetContainerElement> | |
| decltype(auto) | get_element (T &t, const size_t i, SubscriptFunction at=GetContainerElement{}) noexcept |
Returns the ith element if T has a subscript operator, otherwise if T is fundamental or a std::complex of a fundamental type, returns t. More... | |
| template<typename T , typename SizeFunction = GetContainerSize> | |
| decltype(auto) | get_size (const T &t, SizeFunction size=GetContainerSize{}) noexcept |
Retrieve the size of t if t.size() is a valid expression, otherwise if T is fundamental or a std::complex of a fundamental type, returns 1. More... | |
| template<typename Container , typename DestructiveResizeFunction = ContainerDestructiveResize> | |
| void | destructive_resize_components (const gsl::not_null< Container * > container, const size_t new_size, DestructiveResizeFunction destructive_resize=ContainerDestructiveResize{}) noexcept |
| Checks the size of each component of the container, and resizes if necessary. More... | |
| template<typename T > | |
| decltype(auto) | dereference_wrapper (T &&t) |
| Returns the reference object held by a reference wrapper, if a non-reference_wrapper type is passed in then the object is returned. | |
| constexpr bool | equal_within_roundoff (const double a, const double b, const double eps=std::numeric_limits< double >::epsilon() *100.0, const double scale=1.0) noexcept |
Checks if two values a and b are equal within roundoff, by comparing abs(a - b) < (max(abs(a), abs(b)) + scale) * eps. | |
| template<typename Result , typename Classes , typename Base , typename Callable , Requires<(tmpl::size< Classes >::value !=0)> = nullptr> | |
| Result | call_with_dynamic_type (Base *const obj, Callable &&f) noexcept |
| Call a functor with the derived type of a base class pointer. More... | |
| template<typename Fraction , typename T1 , typename T2 > | |
| Fraction | simplest_fraction_in_interval (const T1 &end1, const T2 &end2) noexcept |
| Find the fraction in the supplied interval with the smallest denominator. More... | |
| template<typename T > | |
| std::string | get_output (const T &t) noexcept |
Get the streamed output of t as a std::string | |
| template<class T , class U > | |
| constexpr T | gsl::narrow_cast (U &&u) noexcept |
Cast u to a type T where the cast may result in narrowing. | |
| template<class T , class U > | |
| T | gsl::narrow (U u) |
| A checked version of narrow_cast() that ERRORs if the cast changed the value. | |
| constexpr size_t | operator""_st (const unsigned long long n) |
| Defines the _st size_t suffix. | |
| template<size_t Size, typename T , typename... Args> | |
| constexpr std::array< T, Size > | make_array (Args &&... args) noexcept(noexcept(MakeArray_detail::MakeArray< Size==0 >::template apply< T >(std::make_index_sequence<(Size==0 ? Size :Size - 1)>{}, std::forward< Args >(args)...))) |
Create a std::array<T, Size>{{T(args...), T(args...), ...}} More... | |
| template<size_t Size, typename T > | |
| constexpr auto | make_array (T &&t) noexcept(noexcept(MakeArray_detail::MakeArray< Size==0 >::template apply< std::decay_t< T > >(std::make_index_sequence<(Size==0 ? Size :Size - 1)>{}, std::forward< T >(t)))) -> std::array< std::decay_t< T >, Size > |
Create a std::array<std::decay_t<T>, Size>{{t, t, ...}} More... | |
| template<typename T , typename... V, Requires<(sizeof...(V) > 0)> = nullptr> | |
| constexpr auto | make_array (T &&t, V &&... values) noexcept(noexcept(std::array< std::decay_t< T >, sizeof...(V)+1 >{ {std::forward< T >(t), std::forward< V >(values)...}})) -> std::array< typename std::decay_t< T >, sizeof...(V)+1 > |
| Helper function to initialize a std::array with varying number of arguments. | |
| template<typename T , size_t size, typename Seq > | |
| constexpr std::array< T, size > | make_array (Seq &&seq) noexcept(noexcept(MakeArray_detail::make_array_from_iterator_impl< T, size >(std::forward< Seq >(seq), std::make_index_sequence< size >{}))) |
Create an std::array<T, size> from the first size values of seq More... | |
| template<typename T > | |
| T | number_of_digits (const T number) |
| Returns the number of digits in an integer number. | |
| template<typename CoeffsIterable , typename DataType > | |
| DataType | evaluate_polynomial (const CoeffsIterable &coeffs, const DataType &x) noexcept |
| Evaluate a polynomial \(\sum_{p=0}^N c_p x^p\) with Horner's rule. More... | |
| template<typename T , Requires< std::is_arithmetic< T >::value > = nullptr> | |
| constexpr T | step_function (const T &arg) noexcept |
| Defines the Heaviside step function \(\Theta\) for arithmetic types. \(\Theta(0) = 1\). | |
| template<size_t N, typename DataType > | |
| DataType | smoothstep (const double lower_edge, const double upper_edge, const DataType &arg) noexcept |
Smoothly interpolates from 0 to 1 between lower_edge and upper_edge with a Hermite polynomial of degree 2 * N + 1. More... | |
| template<typename T , Requires< std::is_arithmetic< T >::value or tt::is_a_v< std::complex, T > > = nullptr> | |
| auto | invsqrt (const T &arg) noexcept |
| Defines the inverse square-root ( \(1/\sqrt{x}\)) for arithmetic and complex types. | |
| template<typename T , Requires< std::is_arithmetic< T >::value > = nullptr> | |
| auto | invcbrt (const T &arg) noexcept |
| Defines the inverse cube-root ( \(1/\sqrt[3]{x}\)) for arithmetic types. | |
| template<typename T > | |
| constexpr T | sgn (const T &val) noexcept |
Compute the sign function of val defined as 1 if val > 0, 0 if val == 0, and -1 if val < 0. | |
| template<class ForwardIterator , class T > | |
| constexpr void | cpp2b::iota (ForwardIterator first, ForwardIterator last, T value) |
| template<class InputIt , class T > | |
| constexpr T | cpp2b::accumulate (InputIt first, InputIt last, T init) |
| template<class... Fs> | |
| Overloader< Fs... > | make_overloader (Fs... fs) |
Create Overloader<Fs...>, see Overloader for details. | |
| template<typename ForwardIt , typename Func > | |
| void | sequence_print_helper (std::ostream &out, ForwardIt &&begin, ForwardIt &&end, Func f) noexcept |
| Applies the function f(out, it) to each item from begin to end, separated by commas and surrounded by parens. | |
| template<typename ForwardIt > | |
| void | sequence_print_helper (std::ostream &out, ForwardIt &&begin, ForwardIt &&end) noexcept |
| Prints all the items as a comma separated list surrounded by parens. | |
| template<typename... Ranges, typename Generator > | |
| auto | make_static_cache (Generator &&generator) noexcept |
| Create a StaticCache, inferring the cached type from the generator. | |
| template<typename T , size_t Dim> | |
| std::array< T, Dim - 1 > | all_but_specified_element_of (const std::array< T, Dim > &a, const size_t element_to_remove) noexcept |
| Construct an array from an existing array omitting one element. | |
| template<typename T , size_t Dim> | |
| std::array< T, Dim+1 > | insert_element (std::array< T, Dim > a, const size_t element_to_add, T value) noexcept |
| Construct an array from an existing array adding one element. | |
| template<typename T , size_t Dim> | |
| constexpr std::array< T, Dim+1 > | prepend (const std::array< T, Dim > &a, T value) noexcept |
| Construct an array from an existing array prepending a value. | |
| template<typename T , size_t Dim, typename F > | |
| auto | map_array (const std::array< T, Dim > &array, const F &f) noexcept |
| Applies a function to each element of an array, producing a new array of the results. The elements of the new array are constructed in place, so they need not be default constructible. | |
| template<typename T > | |
| std::ostream & | operator<< (std::ostream &os, const std::list< T > &v) noexcept |
| Output the items of a std::list. | |
| template<typename T > | |
| std::ostream & | operator<< (std::ostream &os, const std::vector< T > &v) noexcept |
| Output the items of a std::vector. | |
| template<typename T > | |
| std::ostream & | operator<< (std::ostream &os, const std::deque< T > &v) noexcept |
| Output the items of a std::deque. | |
| template<typename T , size_t N> | |
| std::ostream & | operator<< (std::ostream &os, const std::array< T, N > &a) noexcept |
| Output the items of a std::array. | |
| template<typename... Args> | |
| std::ostream & | operator<< (std::ostream &os, const std::tuple< Args... > &t) noexcept |
| Stream operator for tuples. | |
| template<typename K , typename V , typename H > | |
| std::ostream & | operator<< (std::ostream &os, const std::unordered_map< K, V, H > &m) noexcept |
| Output all the key, value pairs of a std::unordered_map. | |
| template<typename K , typename V , typename C > | |
| std::ostream & | operator<< (std::ostream &os, const std::map< K, V, C > &m) noexcept |
| Output all the key, value pairs of a std::map. | |
| template<typename T , typename H > | |
| std::ostream & | operator<< (std::ostream &os, const std::unordered_set< T, H > &v) noexcept |
| Output the items of a std::unordered_set. | |
| template<typename T , typename C > | |
| std::ostream & | operator<< (std::ostream &os, const std::set< T, C > &v) noexcept |
| Output the items of a std::set. | |
| template<typename T , Requires< tt::is_streamable< std::ostream, T >::value > > | |
| std::ostream & | operator<< (std::ostream &os, const std::unique_ptr< T > &t) noexcept |
| Stream operator for std::unique_ptr. | |
| template<typename T , Requires< tt::is_streamable< std::ostream, T >::value > > | |
| std::ostream & | operator<< (std::ostream &os, const std::shared_ptr< T > &t) noexcept |
| Stream operator for std::shared_ptr. | |
| template<typename T , typename U > | |
| std::ostream & | operator<< (std::ostream &os, const std::pair< T, U > &t) noexcept |
| Stream operator for std::pair. | |
| template<typename T > | |
| std::ostream & | operator<< (std::ostream &os, const std::optional< T > &t) noexcept |
| Stream operator for std::optional. | |
| template<typename K , typename V , typename H > | |
| std::string | keys_of (const std::unordered_map< K, V, H > &m) |
| Construct a string containing the keys of a std::unordered_map. | |
| template<typename K , typename V , typename C > | |
| std::string | keys_of (const std::map< K, V, C > &m) |
| Construct a string containing the keys of a std::map. | |
| template<typename... Args> | |
| std::string | formatted_string (const std::string &fmt, Args... args) |
| Format a string like printf. More... | |
| std::string | current_date_and_time () |
| Get the current date and time. | |
| void | sys::exit () |
| Exit the program normally. This should only be called once over all processors. | |
| int | sys::number_of_procs () |
| Number of processing elements. | |
| int | sys::my_proc () |
| Index of my processing element. | |
| int | sys::number_of_nodes () |
| Number of nodes. | |
| int | sys::my_node () |
| Index of my node. | |
| int | sys::procs_on_node (const int node_index) |
| Number of processing elements on the given node. | |
| int | sys::my_local_rank () |
| The local index of my processing element on my node. This is in the interval 0, ..., procs_on_node(my_node()) - 1. | |
| int | sys::first_proc_on_node (const int node_index) |
| Index of first processing element on the given node. | |
| int | sys::node_of (const int proc_index) |
| Index of the node for the given processing element. | |
| int | sys::local_rank_of (const int proc_index) |
| The local index for the given processing element on its node. | |
| double | sys::wall_time () |
| The elapsed wall time in seconds. | |
| template<typename... Ts> | |
| constexpr void | expand_pack (Ts &&...) noexcept |
| Allows zero-cost unordered expansion of a parameter. More... | |
| template<typename T , typename... Ts> | |
| constexpr decltype(auto) | get_first_argument (T &&t, Ts &&...) noexcept |
| Returns the first argument of a parameter pack. | |
| template<bool ReverseIteration = false, typename... Elements, typename N_aryOp , typename... Args> | |
| constexpr void | tuple_transform (const std::tuple< Elements... > &tuple, N_aryOp &&op, Args &&... args) noexcept(noexcept(tuple_impl_detail::tuple_transform_impl< ReverseIteration >(tuple, std::forward< N_aryOp >(op), std::make_index_sequence< sizeof...(Elements)>{}, args...))) |
| Perform a transform over a std::tuple. More... | |
| template<size_t Start, size_t Stop, typename Tuple > | |
| constexpr auto | tuple_slice (Tuple &&tuple) noexcept |
The subset of elements in tuple from index Start to (excluding) Stop | |
| template<size_t Size, typename Tuple > | |
| constexpr auto | tuple_head (Tuple &&tuple) noexcept |
The first Size elements in tuple | |
| template<size_t Size, typename Tuple > | |
| constexpr auto | tuple_tail (Tuple &&tuple) noexcept |
The last Size elements in tuple | |
| std::string | wrap_text (std::string str, size_t line_length, const std::string &indentation="") noexcept |
Wrap the string str so that it is no longer than line_length and indent each new line with indentation. The first line is also indented. More... | |
Variables | |
| template<bool... Bs> | |
| constexpr bool | tmpl2::flat_all_v = flat_all<Bs...>::value |
| A non-short-circuiting logical AND between bools 'B"". More... | |
| template<bool... Bs> | |
| constexpr bool | tmpl2::flat_any_v = flat_any<Bs...>::value |
| A non-short-circuiting logical OR between bools 'B"". More... | |
| template<bool UseLibXsmm = false> | |
| void | dgemm_ (const char &TRANSA, const char &TRANSB, const size_t &M, const size_t &N, const size_t &K, const double &ALPHA, const double *A, const size_t &LDA, const double *B, const size_t &LDB, const double &BETA, double *C, const size_t &LDC) |
| Perform a matrix-matrix multiplication. More... | |
| template<> | |
| void | dgemm_< true > (const char &TRANSA, const char &TRANSB, const size_t &M, const size_t &N, const size_t &K, const double &ALPHA, const double *A, const size_t &LDA, const double *B, const size_t &LDB, const double &BETA, double *C, const size_t &LDC) |
| Perform a matrix-matrix multiplication. More... | |
| void | dgemv_ (const char &TRANS, const size_t &M, const size_t &N, const double &ALPHA, const double *A, const size_t &LDA, const double *X, const size_t &INCX, const double &BETA, double *Y, const size_t &INCY) |
| Perform a matrix-vector multiplication. More... | |
| template<class T , std::size_t N, typename Size > | |
| constexpr T & | gsl::at (std::array< T, N > &arr, Size index) |
| Retrieve a entry from a container, with checks in Debug mode that the index being retrieved is valid. | |
| template<class Cont , typename Size > | |
| constexpr const Cont::value_type & | gsl::at (const Cont &cont, Size index) |
| Retrieve a entry from a container, with checks in Debug mode that the index being retrieved is valid. | |
| template<class T , typename Size > | |
| constexpr const T & | gsl::at (std::initializer_list< T > cont, Size index) |
| Retrieve a entry from a container, with checks in Debug mode that the index being retrieved is valid. | |
| template<class ElementType > | |
| constexpr span< ElementType > | gsl::make_span (ElementType *ptr, typename span< ElementType >::index_type count) |
| Utility function for creating spans. | |
| template<class ElementType > | |
| constexpr span< ElementType > | gsl::make_span (ElementType *firstElem, ElementType *lastElem) |
| Utility function for creating spans. | |
| template<class ElementType , std::size_t N> | |
| constexpr span< ElementType, N > | gsl::make_span (ElementType(&arr)[N]) noexcept |
| Utility function for creating spans. | |
| template<class Container > | |
| constexpr span< typename Container::value_type > | gsl::make_span (Container &cont) |
| Utility function for creating spans. | |
| template<class Container > | |
| constexpr span< const typename Container::value_type > | gsl::make_span (const Container &cont) |
| Utility function for creating spans. | |
| template<class Ptr > | |
| constexpr span< typename Ptr::element_type > | gsl::make_span (Ptr &cont, std::ptrdiff_t count) |
| Utility function for creating spans. | |
| template<class Ptr > | |
| constexpr span< typename Ptr::element_type > | gsl::make_span (Ptr &cont) |
| Utility function for creating spans. | |
| template<typename T > | |
| T | make_signaling_NaN (const T &) noexcept |
Returns an appropriate signaling NaN for fundamantal or multi-field types (such as std::complex). | |
| template<typename T > | |
| std::complex< T > | make_signaling_NaN (const std::complex< T > &) noexcept |
Returns an appropriate signaling NaN for fundamantal or multi-field types (such as std::complex). | |
| template<typename T > | |
| T | make_signaling_NaN () noexcept |
Returns an appropriate signaling NaN for fundamantal or multi-field types (such as std::complex). | |
| template<typename ForwardIt , typename Func > | |
| void | unordered_print_helper (std::ostream &out, ForwardIt &&begin, ForwardIt &&end, Func f) noexcept |
| template<typename ForwardIt > | |
| void | unordered_print_helper (std::ostream &out, ForwardIt &&begin, ForwardIt &&end) noexcept |
| template<typename T > | |
| decltype(auto) | magnitude (const std::array< T, 1 > &a) noexcept |
| Euclidean magnitude of the elements of the array. More... | |
| template<typename T > | |
| decltype(auto) | magnitude (const std::array< T, 2 > &a) noexcept |
| Euclidean magnitude of the elements of the array. More... | |
| template<typename T > | |
| decltype(auto) | magnitude (const std::array< T, 3 > &a) noexcept |
| Euclidean magnitude of the elements of the array. More... | |
| template<typename T , typename R > | |
| decltype(auto) | dot (const std::array< T, 1 > &first, const std::array< R, 1 > &second) |
| Dot product between two arrays. More... | |
| template<typename T , typename R > | |
| decltype(auto) | dot (const std::array< T, 2 > &first, const std::array< R, 2 > &second) |
| Dot product between two arrays. More... | |
| template<typename T , typename R > | |
| decltype(auto) | dot (const std::array< T, 3 > &first, const std::array< R, 3 > &second) |
| Dot product between two arrays. More... | |
| template<class Tag , class... Tags> | |
| constexpr const Tag::type & | tuples::get (const TaggedTuple< Tags... > &t) noexcept |
Retrieve the element of Tag in the TaggedTuple. | |
| template<class Tag , class... Tags> | |
| constexpr Tag::type & | tuples::get (TaggedTuple< Tags... > &t) noexcept |
Retrieve the element of Tag in the TaggedTuple. | |
| template<class Tag , class... Tags> | |
| constexpr const Tag::type && | tuples::get (const TaggedTuple< Tags... > &&t) noexcept |
Retrieve the element of Tag in the TaggedTuple. | |
| template<class Tag , class... Tags> | |
| constexpr Tag::type && | tuples::get (TaggedTuple< Tags... > &&t) noexcept |
Retrieve the element of Tag in the TaggedTuple. | |
| template<typename ApplyTags , typename F , typename... Tags> | |
| constexpr decltype(auto) | tuples::apply (F &&f, const TaggedTuple< Tags... > &t) |
Invoke f with the ApplyTags taken from t expanded in a parameter pack. More... | |
| template<typename F , typename... Tags> | |
| constexpr decltype(auto) | tuples::apply (F &&f, const TaggedTuple< Tags... > &t) |
Invoke f with the ApplyTags taken from t expanded in a parameter pack. More... | |
| template<bool ReverseIteration = false, typename... Elements, typename N_aryOp , typename... Args> | |
| constexpr void | tuple_fold (const std::tuple< Elements... > &tuple, N_aryOp &&op, Args &&... args) noexcept(noexcept(tuple_impl_detail::tuple_fold_impl< ReverseIteration >(tuple, std::forward< N_aryOp >(op), std::make_index_sequence< sizeof...(Elements)>{}, args...))) |
| Perform a fold over a std::tuple. More... | |
| template<bool ReverseIteration = false, typename... Elements, typename N_aryOp , typename... Args> | |
| constexpr void | tuple_counted_fold (const std::tuple< Elements... > &tuple, N_aryOp &&op, Args &&... args) noexcept(noexcept(tuple_impl_detail::tuple_counted_fold_impl< ReverseIteration >(tuple, std::forward< N_aryOp >(op), std::make_index_sequence< sizeof...(Elements)>{}, args...))) |
| Perform a fold over a std::tuple. More... | |
| template<typename LhsVectorType , typename RhsVectorType , typename ResultVectorType = typename blaze::MultTrait<LhsVectorType, RhsVectorType>::Type> | |
| void | outer_product (const gsl::not_null< ResultVectorType * > result, const LhsVectorType &lhs, const RhsVectorType &rhs) noexcept |
| Computes the outer product between two vectors. More... | |
| template<typename LhsVectorType , typename RhsVectorType , typename ResultVectorType = typename blaze::MultTrait<LhsVectorType, RhsVectorType>::Type> | |
| ResultVectorType | outer_product (const LhsVectorType &lhs, const RhsVectorType &rhs) noexcept |
| Computes the outer product between two vectors. More... | |
| template<typename VectorType > | |
| void | fill_with_n_copies (const gsl::not_null< VectorType * > result, const VectorType &to_copy, const size_t times_to_copy) noexcept |
Creates or fills a vector with data from to_repeat copied times_to_repeat times in sequence. More... | |
| template<typename VectorType > | |
| VectorType | create_vector_of_n_copies (const VectorType &to_copy, const size_t times_to_copy) noexcept |
Creates or fills a vector with data from to_repeat copied times_to_repeat times in sequence. More... | |
A collection of useful classes, functions and metafunctions.
| #define DEFINE_FAKE_VIRTUAL | ( | function | ) |
Define a function that acts similarly to a virtual function, but can take template parameters.
DEFINE_FAKE_VIRTUAL(func) defines the function fake_virtual_func and the struct FakeVirtualInherit_func. It should usually be called in a detail namespace.
A base class Base using this functionality should define a type
and a member function func wrapping fake_virtual_func, with the wrapper passing the derived classes as a typelist as the first template argument and the this pointer as the first normal argument.
Derived classes should then inherit from Base::Inherit instead of directly from Base. (Base::Inherit inherits from Base.)
If the base class has no pure virtual functions remaining it will generally be desirable to mark the constructors and assignment operators protected so that a bare base class cannot be instantiated.
If it is necessary to use multiple fake virtual functions with the same base class, the Inherit definition can nest the fake virtual classes:
| #define DEFINE_STD_ARRAY_BINOP | ( | RESULT_TYPE, | |
| LTYPE, | |||
| RTYPE, | |||
| OP_FUNCTION_NAME, | |||
| BINARY_OP | |||
| ) |
Declares a binary function on an array, intended for binary operators such as +
| RESULT_TYPE | the value_type that is the result of the operation (e.g. A for resulting std::array<A,2>) |
| LTYPE | the value_type of the first argument of the function (so the left value if the function is an operator overload) |
| RTYPE | the value_type of the second argument of the function |
| OP_FUNCTION_NAME | the function which should be declared (e.g. operator+) |
| BINARY_OP | the binary function which should be applied elementwise to the pair of arrays. (e.g. std::plus<>()) |
| #define DEFINE_STD_ARRAY_INPLACE_BINOP | ( | LTYPE, | |
| RTYPE, | |||
| OP_FUNCTION_NAME, | |||
| BINARY_OP | |||
| ) |
Declares an in-place binary function on an array, intended for operations such as +=
| LTYPE | the value_type of the first argument of the function which is also the result value_tye of the operation (so the left value if the function is an operator overload) |
| RTYPE | the value_type of the second argument of the function |
| OP_FUNCTION_NAME | the function which should be declared (e.g. operator+=) |
| BINARY_OP | the binary function which should be applied elementwise to the pair of arrays. (e.g. std::plus<>()) |
| #define EXPAND_PACK_LEFT_TO_RIGHT | ( | ... | ) | (void)std::initializer_list<char> { ((void)(__VA_ARGS__), '0')... } |
Expand a parameter pack evaluating the terms from left to right.
The parameter pack inside the argument to the macro must not be expanded since the macro will do the expansion correctly for you. In the below example a parameter pack of std::integral_constant<size_t, I> is passed to the function. The closure lambda is used to sum up the values of all the Ts. Note that the Ts passed to EXPAND_PACK_LEFT_TO_RIGHT is not expanded.
| #define GENERATE_INSTANTIATIONS | ( | INSTANTIATION_MACRO, | |
| ... | |||
| ) |
Macro useful for generating many explicit instantiations of function or class templates.
It is often necessary to generate explicit instantiations of function or class templates. Since the total number of explicit instantiations scales as the product of the number of possible number of parameter values of each template parameter, this quickly becomes tedious. This macro allows you to easily generate hundreds of explicit instantiations.
The first argument to the macro is a macro that takes two arguments and is described below. The remaining arguments are macro-tuples, e.g. (1, 2, 3). The Cartesian product of the macro-tuples is then computed and each term is passed as a tuple as the second argument to the INSTANTIATION_MACRO. The first argument to the INSTANTIATION_MACRO is a Boost.Preprocessor internal variable so just make it _. The INSTANTIATION(_, data) macro below serves as an example. A concrete example is generating explicit instantiations of the class Index<Dim> for Dim = 0,1,2,3, which you would do as follows:
This will generate:
It is also possible to generate explicit instantiations for multiple classes or functions in a single call to GENERATE_INSTANTIATIONS. For example, the (in)equivalence operators can be generated using:
which will result in the instantiations:
Now let's look at generating instantiations of member function templates of class templates, which will be a common use case. In this example we generate explicit instantiations of all the member function templates of the class ScalarWave::Solutions::PlaneWave. In total, for Dim = 1,2,3 and types double and DataVector this is about 42 explicit instantiations, which would be extremely annoying to write by hand. The macro code is surprisingly simple:
We don't show the result from preprocessor since for all of the member functions of PlaneWave the total output is approximately 150 lines, but you can hopefully see the benefits of generating explicit instantiations using the GENERATE_INSTANTIATIONS way.
One thing that can be difficult is debugging metaprograms (be they template or macro-based). To this end we provide a make target DebugPreprocessor which prints the output of running the preprocessor on the file src/Executables/DebugPreprocessor/DebugPreprocessor.cpp. Note that the output of the GENERATE_INSTANTIATIONS macro will be on a single line, so it often proves useful to copy-paste the output into an editor and run clang-format over the code so it's easier to reason about.
| #define LIKELY | ( | x | ) | (x) |
The if statement is expected to evaluate true most of the time
| #define UNLIKELY | ( | x | ) | (x) |
The if statement is expected to evaluate false most of the time
| using tmpl2::flat_all = typedef std::is_same<value_list<bool, Bs...>, value_list<bool, (static_cast<void>(Bs), true)...> > |
A non-short-circuiting logical AND between bools 'B"".
Useful when arbitrarily large parameter packs need to be evaluated, since std::conjunction and std::disjunction use recursion
| using tmpl2::flat_any = typedef std::integral_constant< bool, not std::is_same< value_list<bool, Bs...>, value_list<bool, (static_cast<void>(Bs), false)...> >::value> |
A non-short-circuiting logical OR between bools 'B"".
Useful when arbitrarily large parameter packs need to be evaluated, since std::conjunction and std::disjunction use recursion
| using make_boost_variant_over = typename detail::make_boost_variant_over_impl< tmpl::remove_duplicates<Sequence> >::type |
Create a boost::variant with all all the types inside the typelist Sequence.
Returns: boost::variant of all types inside Sequence
| using gsl::owner = typedef typename detail::owner_impl<T>::type |
Mark a raw pointer as owning its data.
gsl::owner. Instead you should use std::unique_ptr, and if shared ownership is required, std::shared_ptr. | using Requires = typename Requires_detail::requires_impl< B>::template_error_type_failed_to_meet_requirements_on_template_parameters |
Express requirements on the template parameters of a function or class, replaces std::enable_if_t
Replacement for std::enable_if_t and Concepts for expressing requirements on template parameters. This does not require merging of the Concepts TS (whose merit is debatable) and provides an "error message" if substitution of a template parameter failed. Specifically, the compiler error will contain "template_error_type_failed_to_meet_requirements_on_template_parameters", aiding the user of a function or class in tracking down the list of requirements on the deduced type.
For example, if a function foo is defined as:
then calling the function with a list, foo(std::list<double>{}); results in the following compilation error from clang:
Here is an example of how write function overloads using Requires or to express constraints on the template parameters:
Requires is safer than using std::enable_if_t because the nested type alias is of type std::nullptr_t and so usage is always:
|
constexpr |
Reimplementation of std::accumulate that is constexpr; taken from the LLVM source at https://github.com/llvm-mirror/libcxx/blob/master/include/numeric
|
constexpr |
Invoke f with the ApplyTags taken from t expanded in a parameter pack.
ApplyTags defaults to the full list of tags in t.
Here is an example how to use the function:
This is the function being called in the above example:
|
constexpr |
Invoke f with the ApplyTags taken from t expanded in a parameter pack.
ApplyTags defaults to the full list of tags in t.
Here is an example how to use the function:
This is the function being called in the above example:
|
noexcept |
Call a functor with the derived type of a base class pointer.
Calls functor with obj cast to type T* where T is the dynamic type of *obj. The decay type of T must be in the provided list of classes.
| Result | the return type |
| Classes | the typelist of derived classes |
|
noexcept |
Creates or fills a vector with data from to_repeat copied times_to_repeat times in sequence.
This can be useful for generating data that consists of the same block of values duplicated a number of times. For instance, this can be used to create a vector representing three-dimensional volume data from a corresponding two-dimensional vector data, if the two-dimensional data corresponds to the two fastest-varying directions of the desired three-dimensional representation. The result would then be uniform in the slowest-varying direction of the three dimensional grid.
|
inline |
The dot product of two vectors.
| N | the length of the vectors. |
| X | a pointer to the first element of the first vector. |
| INCX | the stride for the elements of the first vector. |
| Y | a pointer to the first element of the second vector. |
| INCY | the stride for the elements of the second vector. |
Returns: the dot product of the given vectors.
|
noexcept |
Checks the size of each component of the container, and resizes if necessary.
This operation is not permitted when any of the components of the tensor is non-owning (see VectorImpl for ownership details).
UNLIKELY to perform the checks most quickly when resizing is unnecessary.Tensors, NOT (for instance) DataVectors. For derived classes of VectorImpl, this function will cause no resize. Instead, use the VectorImpl member function VectorImpl::destructive_resize().VectorImpl. If either of those assumptions needs to be relaxed, this function will need to be generalized.
|
inline |
Perform a matrix-matrix multiplication.
Perform the matrix-matrix multiplication
\[ C = \alpha \mathrm{op}(A) \mathrm{op}(B) + \beta \mathrm{op}(C) \]
where \(\mathrm{op}(A)\) represents either \(A\) or \(A^{T}\) (transpose of \(A\)).
LIBXSMM, which is much faster than BLAS for small matrices, can be called instead of BLAS by passing the template parameter true.
| TRANSA | either 'N', 'T' or 'C', transposition of matrix A |
| TRANSB | either 'N', 'T' or 'C', transposition of matrix B |
| M | Number of rows in \(\mathrm{op}(A)\) |
| N | Number of columns in \(\mathrm{op}(B)\) and \(\mathrm{op}(C)\) |
| K | Number of columns in \(\mathrm{op}(A)\) |
| ALPHA | specifies \(\alpha\) |
| A | Matrix \(A\) |
| LDA | Specifies first dimension of \(\mathrm{op}(A)\) |
| B | Matrix \(B\) |
| LDB | Specifies first dimension of \(\mathrm{op}(B)\) |
| BETA | specifies \(\beta\) |
| C | Matrix \(C\) |
| LDC | Specifies first dimension of \(\mathrm{op}(C)\) |
| UseLibXsmm | if true then use LIBXSMM |
|
inline |
Perform a matrix-matrix multiplication.
Perform the matrix-matrix multiplication
\[ C = \alpha \mathrm{op}(A) \mathrm{op}(B) + \beta \mathrm{op}(C) \]
where \(\mathrm{op}(A)\) represents either \(A\) or \(A^{T}\) (transpose of \(A\)).
LIBXSMM, which is much faster than BLAS for small matrices, can be called instead of BLAS by passing the template parameter true.
| TRANSA | either 'N', 'T' or 'C', transposition of matrix A |
| TRANSB | either 'N', 'T' or 'C', transposition of matrix B |
| M | Number of rows in \(\mathrm{op}(A)\) |
| N | Number of columns in \(\mathrm{op}(B)\) and \(\mathrm{op}(C)\) |
| K | Number of columns in \(\mathrm{op}(A)\) |
| ALPHA | specifies \(\alpha\) |
| A | Matrix \(A\) |
| LDA | Specifies first dimension of \(\mathrm{op}(A)\) |
| B | Matrix \(B\) |
| LDB | Specifies first dimension of \(\mathrm{op}(B)\) |
| BETA | specifies \(\beta\) |
| C | Matrix \(C\) |
| LDC | Specifies first dimension of \(\mathrm{op}(C)\) |
| UseLibXsmm | if true then use LIBXSMM |
|
inline |
Perform a matrix-vector multiplication.
\[ y = \alpha \mathrm{op}(A) x + \beta y \]
where \(\mathrm{op}(A)\) represents either \(A\) or \(A^{T}\) (transpose of \(A\)).
| TRANS | either 'N', 'T' or 'C', transposition of matrix A |
| M | Number of rows in \(\mathrm{op}(A)\) |
| N | Number of columns in \(\mathrm{op}(A)\) |
| ALPHA | specifies \(\alpha\) |
| A | Matrix \(A\) |
| LDA | Specifies first dimension of \(\mathrm{op}(A)\) |
| X | Vector \(x\) |
| INCX | Specifies the increment for the elements of \(x\) |
| BETA | Specifies \(\beta\) |
| Y | Vector \(y\) |
| INCY | Specifies the increment for the elements of \(y\) |
| decltype(auto) dot | ( | const std::array< T, 1 > & | first, |
| const std::array< R, 1 > & | second | ||
| ) |
Dot product between two arrays.
This also works elementwise if T is a container and R is a float or the other way round. The return type will always be the same as the return type of the multiplication which may be a blaze expression template.
| decltype(auto) dot | ( | const std::array< T, 2 > & | first, |
| const std::array< R, 2 > & | second | ||
| ) |
Dot product between two arrays.
This also works elementwise if T is a container and R is a float or the other way round. The return type will always be the same as the return type of the multiplication which may be a blaze expression template.
| decltype(auto) dot | ( | const std::array< T, 3 > & | first, |
| const std::array< R, 3 > & | second | ||
| ) |
Dot product between two arrays.
This also works elementwise if T is a container and R is a float or the other way round. The return type will always be the same as the return type of the multiplication which may be a blaze expression template.
|
noexcept |
Evaluate a polynomial \(\sum_{p=0}^N c_p x^p\) with Horner's rule.
| coeffs | The polynomial coefficients \(c_p\) ordered from constant to largest power |
| x | The polynomial variable \(x\) |
| CoeffsIterable | The type of the polynomial coefficients coeffs. Can be a std::vector<double> or std::array<double>, which means the coefficients are constant for all values in x. Each coefficient can also be a vector type of typically the same size as x, which means the coefficients vary with the elements in x. |
| DataType | The type of the polynomial variable x. Must support make_with_value<DataType, DataType>, as well as (elementwise) addition with CoeffsIterable::value_type and multiplication with DataType. |
|
constexprnoexcept |
Allows zero-cost unordered expansion of a parameter.
Expands a parameter pack, typically useful for runtime evaluation via a Callable such as a lambda, function, or function object. For example, an unordered transform of a std::tuple can be implemented as:
|
noexcept |
Creates or fills a vector with data from to_repeat copied times_to_repeat times in sequence.
This can be useful for generating data that consists of the same block of values duplicated a number of times. For instance, this can be used to create a vector representing three-dimensional volume data from a corresponding two-dimensional vector data, if the two-dimensional data corresponds to the two fastest-varying directions of the desired three-dimensional representation. The result would then be uniform in the slowest-varying direction of the three dimensional grid.
|
constexpr |
Reimplementation of std::find that is constexpr
|
constexpr |
Reimplementation of std::find_if that is constexpr
|
constexpr |
Reimplementation of std::find_if_not that is constexpr
| std::string formatted_string | ( | const std::string & | fmt, |
| Args... | args | ||
| ) |
Format a string like printf.
Given a formatting string and arguments this returns the corresponding string. Similar to printf but using std::strings.
|
noexcept |
Returns the ith element if T has a subscript operator, otherwise if T is fundamental or a std::complex of a fundamental type, returns t.
This function also optionally takes the user-defined subscript function at, which can be used to specify a custom indexing function. For instance, for a type which is a std::array of a std::arrays, the indexing function could be the below callable struct:
which would index the data structure in a manner in which the outer array index varies fastest. The indexing function must take as arguments the applicable container and a size_t index, in that order. This follows the convention of gsl::at.
std::complex are regarded as non-indexable (despite a predictable memory layout), so this function acts as the identity on std::complex of fundamental types
|
noexcept |
Retrieve the size of t if t.size() is a valid expression, otherwise if T is fundamental or a std::complex of a fundamental type, returns 1.
This function also optionally takes the user-defined size function, which can be used to specify a custom size function. For instance, for a type which is a std::array of a std::array, the size function could be the below callable struct:
The size function must take the single argument of the applicable container, and should return a size_t. This follows the convention of std::size() as of C++17.
std::complex are regarded as non-indexable (despite a predictable memory layout), so this function will return 1 for a std::complex of a fundamental type
|
constexpr |
Reimplementation of std::iota that is constexpr; taken from the LLVM source at https://github.com/llvm-mirror/libcxx/blob/master/include/numeric
|
constexpr |
Reimplementation of std::iter_swap that is constexpr; taken from the LLVM source at https://github.com/llvm-mirror/libcxx/blob/master/include/type_traits
|
noexcept |
Euclidean magnitude of the elements of the array.
If T is a container the magnitude is computed separately for each element of the container.
Requires: If T is a container, T must have following mathematical operators: abs(), sqrt(), and element-wise addition and multiplication. In addition, each T in the array must have the same size.
|
noexcept |
Euclidean magnitude of the elements of the array.
If T is a container the magnitude is computed separately for each element of the container.
Requires: If T is a container, T must have following mathematical operators: abs(), sqrt(), and element-wise addition and multiplication. In addition, each T in the array must have the same size.
|
noexcept |
Euclidean magnitude of the elements of the array.
If T is a container the magnitude is computed separately for each element of the container.
Requires: If T is a container, T must have following mathematical operators: abs(), sqrt(), and element-wise addition and multiplication. In addition, each T in the array must have the same size.
|
constexprnoexcept |
Create a std::array<T, Size>{{T(args...), T(args...), ...}}
| Size | the size of the array |
| T | the type of the element in the array |
|
constexprnoexcept |
Create an std::array<T, size> from the first size values of seq
Requires: Seq has a begin function
| T | the type held by the array |
| size | the size of the created array |
|
constexprnoexcept |
Create a std::array<std::decay_t<T>, Size>{{t, t, ...}}
| Size | the size of the array |
|
constexpr |
Reimplementation of std::next_permutation that is constexpr, with less as the comparator; taken from the LLVM source at https://github.com/llvm-mirror/libcxx/blob/master/include/algorithm
|
constexpr |
Reimplementation of std::next_permutation that is constexpr, for a generic comparator; taken from the LLVM source at https://github.com/llvm-mirror/libcxx/blob/master/include/algorithm
|
noexcept |
Computes the outer product between two vectors.
For vectors \(A\) and \(B\), the resulting outer product is \(\{A_1 B_1,\, A_2 B_1\, \dots\, A_N B_1,\, A_1 B_2\, \dots\, A_N B_M\}\). This is useful for generating separable volume data from its constituent inputs.
|
noexcept |
Computes the outer product between two vectors.
For vectors \(A\) and \(B\), the resulting outer product is \(\{A_1 B_1,\, A_2 B_1\, \dots\, A_N B_1,\, A_1 B_2\, \dots\, A_N B_M\}\). This is useful for generating separable volume data from its constituent inputs.
|
constexpr |
Reimplementation of std::reverse that is constexpr; taken from the LLVM source at https://github.com/llvm-mirror/libcxx/blob/master/include/algorithm
|
noexcept |
Find the fraction in the supplied interval with the smallest denominator.
The endpoints are considered to be in the interval. The order of the arguments is not significant. The answer is unique as long as the interval has length less than 1; for longer intervals, an integer in the range will be returned.
|
noexcept |
Smoothly interpolates from 0 to 1 between lower_edge and upper_edge with a Hermite polynomial of degree 2 * N + 1.
The smoothstep function is
\begin{align*} S_N(x) = \begin{cases} 0 &\quad \text{for} \quad x\leq x_0 \\ \tilde{S}_N((x - x_0) / (x_1 - x_0)) &\quad \text{for} \quad x_0 \leq x\leq x_1 \\ 1 &\quad \text{for} \quad x_1\leq x \\ \end{cases} \end{align*}
where \(x_0\) is lower_edge, \(x_1\) is upper_edge, and, up to \(N=3\),
\begin{align*} \tilde{S}_0(x) &= x \\ \tilde{S}_1(x) &= 3x^2 - 2x^3 \\ \tilde{S}_2(x) &= 10x^3 - 15x^4 + 6x^5 \\ \tilde{S}_3(x) &= 35x^4 - 84x^5 + 70x^6 - 20x^7 \text{.} \end{align*}
|
constexprnoexcept |
Reimplementation of std::swap that is constexpr; taken from the LLVM source at https://github.com/llvm-mirror/libcxx/blob/master/include/type_traits
|
inlineconstexprnoexcept |
Perform a fold over a std::tuple.
Iterates over the elements in a std::tuple tuple from left to right (left fold) calling op(element, args...) on each element in tuple. A right fold can be done by explicitly setting the first template parameter to true. Folds are easily implemented using tuple_fold by updating one of the args... at each iteration. If you need the index of the current element you can use the tuple_counted_fold variant. tuple_counted_fold passes the current index as the second argument to the Callable op. That is, op(element, index, args...).
The sum of a std::tuple of Arithmetics can be computed in several ways. First, you can use a lambda:
You'll notice that state is taken by reference and mutated.
You can do the same thing with a struct defined as
and then using an instance of the struct
tuple_fold or tuple_counted_fold because you cannot pass a pointer to a function template, only a function.
|
inlineconstexprnoexcept |
Perform a fold over a std::tuple.
Iterates over the elements in a std::tuple tuple from left to right (left fold) calling op(element, args...) on each element in tuple. A right fold can be done by explicitly setting the first template parameter to true. Folds are easily implemented using tuple_fold by updating one of the args... at each iteration. If you need the index of the current element you can use the tuple_counted_fold variant. tuple_counted_fold passes the current index as the second argument to the Callable op. That is, op(element, index, args...).
The sum of a std::tuple of Arithmetics can be computed in several ways. First, you can use a lambda:
You'll notice that state is taken by reference and mutated.
You can do the same thing with a struct defined as
and then using an instance of the struct
tuple_fold or tuple_counted_fold because you cannot pass a pointer to a function template, only a function.
|
inlineconstexprnoexcept |
Perform a transform over a std::tuple.
Iterates over the elements in a std::tuple tuple from left to right calling op.operator()(element, index, args...) on each element in tuple. A right-to-left transform can be done by explicitly setting the first template parameter to true. The second argument of the invokable will be a deduced std::integral_constant<size_t, value>, from which the current index can be extracted by using decltype(index)::value. For a function object the decltype(index) can be replaced by the deduced type of index. For example,
Using tuple_transform with a generic lambda goes as follows,
|
noexcept |
Like sequence_print_helper, but sorts the string representations.
|
noexcept |
Like sequence_print_helper, but sorts the string representations.
|
noexcept |
Wrap the string str so that it is no longer than line_length and indent each new line with indentation. The first line is also indented.
Single words longer than line_length are hyphenated.
|
constexpr |
A non-short-circuiting logical AND between bools 'B"".
Useful when arbitrarily large parameter packs need to be evaluated, since std::conjunction and std::disjunction use recursion
|
constexpr |
A non-short-circuiting logical OR between bools 'B"".
Useful when arbitrarily large parameter packs need to be evaluated, since std::conjunction and std::disjunction use recursion