Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 09:52:53

0001 /*!
0002 @file
0003 Forward declares `boost::hana::Sequence`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_HANA_FWD_CONCEPT_SEQUENCE_HPP
0011 #define BOOST_HANA_FWD_CONCEPT_SEQUENCE_HPP
0012 
0013 #include <boost/hana/config.hpp>
0014 #include <boost/hana/core/when.hpp>
0015 
0016 
0017 namespace boost { namespace hana {
0018     //! @ingroup group-concepts
0019     //! @defgroup group-Sequence Sequence
0020     //! The `Sequence` concept represents generic index-based sequences.
0021     //!
0022     //! Compared to other abstract concepts, the Sequence concept is very
0023     //! specific. It represents generic index-based sequences. The reason
0024     //! why such a specific concept is provided is because there are a lot
0025     //! of models that behave exactly the same while being implemented in
0026     //! wildly different ways. It is useful to regroup all those data types
0027     //! under the same umbrella for the purpose of generic programming.
0028     //!
0029     //! In fact, models of this concept are not only _similar_. They are
0030     //! actually _isomorphic_, in a sense that we define below, which is
0031     //! a fancy way of rigorously saying that they behave exactly the same
0032     //! to an external observer.
0033     //!
0034     //!
0035     //! Minimal complete definition
0036     //! ---------------------------
0037     //! `Iterable`, `Foldable`, and `make`
0038     //!
0039     //! The `Sequence` concept does not provide basic methods that could be
0040     //! used as a minimal complete definition; instead, it borrows methods
0041     //! from other concepts and add laws to them. For this reason, it is
0042     //! necessary to specialize the `Sequence` metafunction in Hana's
0043     //! namespace to tell Hana that a type is indeed a `Sequence`. Explicitly
0044     //! specializing the `Sequence` metafunction can be seen like a seal
0045     //! saying "this data type satisfies the additional laws of a `Sequence`",
0046     //! since those can't be checked by Hana automatically.
0047     //!
0048     //!
0049     //! Laws
0050     //! ----
0051     //! The laws for being a `Sequence` are simple, and their goal is to
0052     //! restrict the semantics that can be associated to the functions
0053     //! provided by other concepts. First, a `Sequence` must be a finite
0054     //! `Iterable` (thus a `Foldable` too). Secondly, for a `Sequence` tag
0055     //! `S`, `make<S>(x1, ..., xn)` must be an object of tag `S` and whose
0056     //! linearization is `[x1, ..., xn]`. This basically ensures that objects
0057     //! of tag `S` are equivalent to their linearization, and that they can
0058     //! be created from such a linearization (with `make`).
0059     //!
0060     //! While it would be possible in theory to handle infinite sequences,
0061     //! doing so complicates the implementation of many algorithms. For
0062     //! simplicity, the current version of the library only handles finite
0063     //! sequences. However, note that this does not affect in any way the
0064     //! potential for having infinite `Searchable`s and `Iterable`s.
0065     //!
0066     //!
0067     //! Refined concepts
0068     //! ----------------
0069     //! 1. `Comparable` (definition provided automatically)\n
0070     //! Two `Sequence`s are equal if and only if they contain the same number
0071     //! of elements and their elements at any given index are equal.
0072     //! @include example/sequence/comparable.cpp
0073     //!
0074     //! 2. `Orderable` (definition provided automatically)\n
0075     //! `Sequence`s are ordered using the traditional lexicographical ordering.
0076     //! @include example/sequence/orderable.cpp
0077     //!
0078     //! 3. `Functor` (definition provided automatically)\n
0079     //! `Sequence`s implement `transform` as the mapping of a function over
0080     //! each element of the sequence. This is somewhat equivalent to what
0081     //! `std::transform` does to ranges of iterators. Also note that mapping
0082     //! a function over an empty sequence returns an empty sequence and never
0083     //! applies the function, as would be expected.
0084     //! @include example/sequence/functor.cpp
0085     //!
0086     //! 4. `Applicative` (definition provided automatically)\n
0087     //! First, `lift`ing a value into a `Sequence` is the same as creating a
0088     //! singleton sequence containing that value. Second, applying a sequence
0089     //! of functions to a sequence of values will apply each function to
0090     //! all the values in the sequence, and then return a list of all the
0091     //! results. In other words,
0092     //! @code
0093     //!     ap([f1, ..., fN], [x1, ..., xM]) == [
0094     //!         f1(x1), ..., f1(xM),
0095     //!         ...
0096     //!         fN(x1), ..., fN(xM)
0097     //!     ]
0098     //! @endcode
0099     //! Example:
0100     //! @include example/sequence/applicative.cpp
0101     //!
0102     //! 5. `Monad` (definition provided automatically)\n
0103     //! First, `flaten`ning a `Sequence` takes a sequence of sequences and
0104     //! concatenates them to get a larger sequence. In other words,
0105     //! @code
0106     //!     flatten([[a1, ..., aN], ..., [z1, ..., zM]]) == [
0107     //!         a1, ..., aN, ..., z1, ..., zM
0108     //!     ]
0109     //! @endcode
0110     //! This acts like a `std::tuple_cat` function, except it receives a
0111     //! sequence of sequences instead of a variadic pack of sequences to
0112     //! flatten.\n
0113     //! __Example__:
0114     //! @include example/sequence/monad.ints.cpp
0115     //! Also note that the model of `Monad` for `Sequence`s can be seen as
0116     //! modeling nondeterminism. A nondeterministic computation can be
0117     //! modeled as a function which returns a sequence of possible results.
0118     //! In this line of thought, `chain`ing a sequence of values into such
0119     //! a function will return a sequence of all the possible output values,
0120     //! i.e. a sequence of all the values applied to all the functions in
0121     //! the sequences.\n
0122     //! __Example__:
0123     //! @include example/sequence/monad.types.cpp
0124     //!
0125     //! 6. `MonadPlus` (definition provided automatically)\n
0126     //! `Sequence`s are models of the `MonadPlus` concept by considering the
0127     //! empty sequence as the unit of `concat`, and sequence concatenation
0128     //! as `concat`.
0129     //! @include example/sequence/monad_plus.cpp
0130     //!
0131     //! 7. `Foldable`\n
0132     //! The model of `Foldable` for `Sequence`s is uniquely determined by the
0133     //! model of `Iterable`.
0134     //! @include example/sequence/foldable.cpp
0135     //!
0136     //! 8. `Iterable`\n
0137     //! The model of `Iterable` for `Sequence`s corresponds to iteration over
0138     //! each element of the sequence, in order. This model is not provided
0139     //! automatically, and it is in fact part of the minimal complete
0140     //! definition for the `Sequence` concept.
0141     //! @include example/sequence/iterable.cpp
0142     //!
0143     //! 9. `Searchable` (definition provided automatically)\n
0144     //! Searching through a `Sequence` is equivalent to just searching through
0145     //! a list of the values it contains. The keys and the values on which
0146     //! the search is performed are both the elements of the sequence.
0147     //! @include example/sequence/searchable.cpp
0148     //!
0149     //!
0150     //! Concrete models
0151     //! ---------------
0152     //! `hana::tuple`
0153     //!
0154     //!
0155     //! [1]: http://en.wikipedia.org/wiki/Isomorphism#Isomorphism_vs._bijective_morphism
0156 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0157     template <typename S>
0158     struct Sequence;
0159 #else
0160     template <typename S, typename = void>
0161     struct Sequence : Sequence<S, when<true>> { };
0162 #endif
0163 }} // end namespace boost::hana
0164 
0165 #endif // !BOOST_HANA_FWD_CONCEPT_SEQUENCE_HPP