generate.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // Copyright Neil Groves 2009. Use, modification and
  2. // distribution is subject to the Boost Software License, Version
  3. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. //
  6. //
  7. // For more information, see http://www.boost.org/libs/range/
  8. //
  9. #ifndef BOOST_RANGE_ALGORITHM_GENERATE_HPP_INCLUDED
  10. #define BOOST_RANGE_ALGORITHM_GENERATE_HPP_INCLUDED
  11. #include <boost/concept_check.hpp>
  12. #include <boost/range/begin.hpp>
  13. #include <boost/range/end.hpp>
  14. #include <boost/range/concepts.hpp>
  15. #include <algorithm>
  16. namespace boost
  17. {
  18. namespace range
  19. {
  20. /// \brief template function generate
  21. ///
  22. /// range-based version of the generate std algorithm
  23. ///
  24. /// \pre ForwardRange is a model of the ForwardRangeConcept
  25. /// \pre Generator is a model of the UnaryFunctionConcept
  26. template< class ForwardRange, class Generator >
  27. inline ForwardRange& generate( ForwardRange& rng, Generator gen )
  28. {
  29. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<ForwardRange> ));
  30. std::generate(boost::begin(rng), boost::end(rng), gen);
  31. return rng;
  32. }
  33. /// \overload
  34. template< class ForwardRange, class Generator >
  35. inline const ForwardRange& generate( const ForwardRange& rng, Generator gen )
  36. {
  37. BOOST_RANGE_CONCEPT_ASSERT(( ForwardRangeConcept<const ForwardRange> ));
  38. std::generate(boost::begin(rng), boost::end(rng), gen);
  39. return rng;
  40. }
  41. } // namespace range
  42. using range::generate;
  43. } // namespace boost
  44. #endif // include guard