Mirror reflection library - Lagoon run-time layer 0.5.13

lagoon/range/until.hpp

Go to the documentation of this file.
00001 
00011 #ifndef LAGOON_RANGE_UNTIL_1011291729_HPP
00012 #define LAGOON_RANGE_UNTIL_1011291729_HPP
00013 
00014 #include <lagoon/range/utils.hpp>
00015 #include <cassert>
00016 
00017 LAGOON_NAMESPACE_BEGIN
00018 
00019 namespace aux {
00020 
00021 template <class Range, class Predicate>
00022 struct preceding : public leaping_base
00023 {
00024 private:
00025     Range range;
00026     Predicate predicate;
00027     bool done;
00028 
00029     bool is_done(void) const
00030     {
00031         return range.empty() ? true : predicate(range.front());
00032     }
00033 public:
00034     preceding(preceding&& other)
00035      : range(std::move(other.range))
00036      , predicate(std::move(other.predicate))
00037      , done(other.done)
00038     { }
00039 
00040     preceding(const Range& rng, const Predicate& pred)
00041      : range(rng)
00042      , predicate(pred)
00043      , done(is_done())
00044     { }
00045 
00046     preceding(Range&& rng, Predicate&& pred)
00047      : range(std::forward(rng))
00048      , predicate(std::forward(pred))
00049      , done(is_done())
00050     { }
00051 
00052     inline bool empty(void) const
00053     {
00054         return done || range.empty();
00055     }
00056 
00057     void step_front(void)
00058     {
00059         assert(!empty());
00060         range.step_front();
00061         done = is_done();
00062     }
00063 
00064     size_t leap_front(size_t leap)
00065     {
00066         return leaping_base::do_leap_front(*this, leap);
00067     }
00068 
00069     inline auto front(void) const -> decltype(range.front())
00070     {
00071         return range.front();
00072     }
00073 
00074     friend inline bool same_position(
00075         const preceding& a,
00076         const preceding& b
00077     )
00078     {
00079         return same_position(a.range, b.range);
00080     }
00081 };
00082 
00083 } // namespace aux
00084 
00085 
00086 #ifdef MIRROR_DOCUMENTATION_ONLY
00087 
00088 
00096 template <class Range, typename Predicate>
00097 UnspecifiedRange until(Range range, Predicate predicate);
00098 #else
00099 template <class Range, typename Predicate>
00100 inline aux::preceding<Range, Predicate>
00101 until(Range range, Predicate predicate)
00102 {
00103     return aux::preceding<Range, Predicate>(range, predicate);
00104 }
00105 #endif
00106 
00107 LAGOON_NAMESPACE_END
00108 
00109 #endif //include guard
00110 

Copyright © 2006-2011 Matus Chochlik, University of Zilina, Zilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Fri Dec 16 2011 by Doxygen (version 1.7.3).
Important note: Although the 'boostified' version of Mirror uses the Boost C++ libraries Coding Guidelines and is implemented inside of the boost namespace, it IS NOT an officially reviewed and accepted Boost library. Mirror is being developed with the intention to be submitted for review for inclusion to the Boost C++ libraries.