Unnamed: 0
int64 0
0
| repo_id
stringlengths 5
186
| file_path
stringlengths 15
223
| content
stringlengths 1
32.8M
⌀ |
---|---|---|---|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/fold_left.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2021-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#ifndef RANGES_V3_ALGORITHM_FOLD_LEFT_HPP
#define RANGES_V3_ALGORITHM_FOLD_LEFT_HPP
#include <meta/meta.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/utility/optional.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
// clang-format off
/// \concept indirectly_binary_left_foldable_impl
/// \brief The \c indirectly_binary_left_foldable_impl concept
template<class F, class T, class I, class U>
CPP_concept indirectly_binary_left_foldable_impl =
movable<T> &&
movable<U> &&
convertible_to<T, U> &&
invocable<F&, U, iter_reference_t<I>> &&
assignable_from<U&, invoke_result_t<F&, U, iter_reference_t<I>>>;
/// \concept indirectly_binary_left_foldable
/// \brief The \c indirectly_binary_left_foldable concept
template<class F, class T, class I>
CPP_concept indirectly_binary_left_foldable =
copy_constructible<F> &&
indirectly_readable<I> &&
invocable<F&, T, iter_reference_t<I>> &&
convertible_to<invoke_result_t<F&, T, iter_reference_t<I>>,
std::decay_t<invoke_result_t<F&, T, iter_reference_t<I>>>> &&
indirectly_binary_left_foldable_impl<F, T, I, std::decay_t<invoke_result_t<F&, T, iter_reference_t<I>>>>;
// clang-format on
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(fold_left)
template(typename I, typename S, typename T, typename Op)(
requires sentinel_for<S, I> AND input_iterator<I> AND
indirectly_binary_left_foldable<Op, T, I>) //
constexpr auto
RANGES_FUNC(fold_left)(I first, S last, T init, Op op)
{
using U = std::decay_t<invoke_result_t<Op &, T, iter_reference_t<I>>>;
if(first == last)
{
return U(std::move(init));
}
U accum = invoke(op, std::move(init), *first);
for(++first; first != last; ++first)
{
accum = invoke(op, std::move(accum), *first);
}
return accum;
}
template(typename Rng, typename T, typename Op)(
requires input_range<Rng> AND
indirectly_binary_left_foldable<Op, T, iterator_t<Rng>>) //
constexpr auto
RANGES_FUNC(fold_left)(Rng && rng, T init, Op op)
{
return (*this)(begin(rng), end(rng), std::move(init), std::move(op));
}
RANGES_FUNC_END(fold_left)
RANGES_FUNC_BEGIN(fold_left_first)
template(typename I, typename S, typename Op)(
requires sentinel_for<S, I> AND input_iterator<I> AND
indirectly_binary_left_foldable<Op, iter_value_t<I>, I>
AND constructible_from<iter_value_t<I>, iter_reference_t<I>>) //
constexpr auto
RANGES_FUNC(fold_left_first)(I first, S last, Op op)
{
using U = invoke_result_t<fold_left_fn, I, S, iter_value_t<I>, Op>;
if(first == last)
{
return optional<U>();
}
iter_value_t<I> init = *first;
++first;
return optional<U>(
in_place,
fold_left_fn{}(std::move(first), std::move(last), std::move(init), op));
}
template(typename R, typename Op)(
requires input_range<R> AND
indirectly_binary_left_foldable<Op, range_value_t<R>, iterator_t<R>>
AND constructible_from<range_value_t<R>, range_reference_t<R>>) //
constexpr auto
RANGES_FUNC(fold_left_first)(R && rng, Op op)
{
return (*this)(begin(rng), end(rng), std::move(op));
}
RANGES_FUNC_END(fold_left_first)
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/swap_ranges.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_SWAP_RANGES_HPP
#define RANGES_V3_ALGORITHM_SWAP_RANGES_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I1, typename I2>
using swap_ranges_result = detail::in1_in2_result<I1, I2>;
RANGES_FUNC_BEGIN(swap_ranges)
/// \brief function template \c swap_ranges
template(typename I1, typename S1, typename I2)(
requires input_iterator<I1> AND sentinel_for<S1, I1> AND
input_iterator<I2> AND indirectly_swappable<I1, I2>)
constexpr swap_ranges_result<I1, I2> //
RANGES_FUNC(swap_ranges)(I1 begin1, S1 end1, I2 begin2) //
{
for(; begin1 != end1; ++begin1, ++begin2)
ranges::iter_swap(begin1, begin2);
return {begin1, begin2};
}
/// \overload
template(typename I1, typename S1, typename I2, typename S2)(
requires input_iterator<I1> AND sentinel_for<S1, I1> AND
input_iterator<I2> AND sentinel_for<S2, I2> AND
indirectly_swappable<I1, I2>)
constexpr swap_ranges_result<I1, I2> RANGES_FUNC(swap_ranges)(I1 begin1,
S1 end1,
I2 begin2,
S2 end2) //
{
for(; begin1 != end1 && begin2 != end2; ++begin1, ++begin2)
ranges::iter_swap(begin1, begin2);
return {begin1, begin2};
}
template(typename Rng1, typename I2_)(
requires input_range<Rng1> AND input_iterator<uncvref_t<I2_>> AND
indirectly_swappable<iterator_t<Rng1>, uncvref_t<I2_>>)
constexpr swap_ranges_result<iterator_t<Rng1>, uncvref_t<I2_>> //
RANGES_FUNC(swap_ranges)(Rng1 && rng1, I2_ && begin2) //
{
return (*this)(begin(rng1), end(rng1), (I2_ &&) begin2);
}
template(typename Rng1, typename Rng2)(
requires input_range<Rng1> AND input_range<Rng2> AND
indirectly_swappable<iterator_t<Rng1>, iterator_t<Rng2>>)
constexpr swap_ranges_result<borrowed_iterator_t<Rng1>, borrowed_iterator_t<Rng2>> //
RANGES_FUNC(swap_ranges)(Rng1 && rng1, Rng2 && rng2) //
{
return (*this)(begin(rng1), end(rng1), begin(rng2), end(rng2));
}
RANGES_FUNC_END(swap_ranges)
namespace cpp20
{
using ranges::swap_ranges;
using ranges::swap_ranges_result;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/starts_with.hpp | // Range v3 library
//
// Copyright 2019 Christopher Di Bella
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#ifndef RANGES_V3_ALGORITHM_STARTS_WITH_HPP
#define RANGES_V3_ALGORITHM_STARTS_WITH_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/equal.hpp>
#include <range/v3/algorithm/mismatch.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
// template<typename I1, typename I2>
// struct starts_with_result : detail::in1_in2_result<I1, I2>
// {
// bool result;
// };
RANGES_FUNC_BEGIN(starts_with)
/// \brief function template \c starts_with
template(typename I1,
typename S1,
typename I2,
typename S2,
typename Comp = equal_to,
typename Proj1 = identity,
typename Proj2 = identity)(
requires input_iterator<I1> AND sentinel_for<S1, I1> AND
input_iterator<I2> AND sentinel_for<S2, I2> AND
indirectly_comparable<I1, I2, Comp, Proj1, Proj2>)
constexpr bool RANGES_FUNC(starts_with)(I1 first1,
S1 last1,
I2 first2,
S2 last2,
Comp comp = {},
Proj1 proj1 = {},
Proj2 proj2 = {}) //
{
return mismatch(std::move(first1),
std::move(last1),
std::move(first2),
last2,
std::move(comp),
std::move(proj1),
std::move(proj2))
.in2 == last2;
}
/// \overload
template(typename R1,
typename R2,
typename Comp = equal_to,
typename Proj1 = identity,
typename Proj2 = identity)(
requires input_range<R1> AND input_range<R2> AND
indirectly_comparable<iterator_t<R1>, iterator_t<R2>, Comp, Proj1, Proj2>)
constexpr bool RANGES_FUNC(starts_with)(
R1 && r1, R2 && r2, Comp comp = {}, Proj1 proj1 = {}, Proj2 proj2 = {}) //
{
return (*this)( //
begin(r1),
end(r1),
begin(r2),
end(r2),
std::move(comp),
std::move(proj1),
std::move(proj2));
}
RANGES_FUNC_END(starts_with)
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif // RANGES_V3_ALGORITHM_STARTS_WITH_HPP
|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/replace.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_REPLACE_HPP
#define RANGES_V3_ALGORITHM_REPLACE_HPP
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(replace)
/// \brief function template \c replace
template(typename I, typename S, typename T1, typename T2, typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
indirectly_writable<I, T2 const &> AND
indirect_relation<equal_to, projected<I, P>, T1 const *>)
constexpr I RANGES_FUNC(replace)(
I first, S last, T1 const & old_value, T2 const & new_value, P proj = {}) //
{
for(; first != last; ++first)
if(invoke(proj, *first) == old_value)
*first = new_value;
return first;
}
/// \overload
template(typename Rng, typename T1, typename T2, typename P = identity)(
requires input_range<Rng> AND
indirectly_writable<iterator_t<Rng>, T2 const &> AND
indirect_relation<equal_to, projected<iterator_t<Rng>, P>, T1 const *>)
constexpr borrowed_iterator_t<Rng> RANGES_FUNC(replace)(
Rng && rng, T1 const & old_value, T2 const & new_value, P proj = {}) //
{
return (*this)(begin(rng), end(rng), old_value, new_value, std::move(proj));
}
RANGES_FUNC_END(replace)
namespace cpp20
{
using ranges::replace;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/contains_subrange.hpp | /// \file
// Range v3 library
//
// Copyright Google LLC, 2021
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_CONTAINS_SUBRANGE_HPP
#define RANGES_V3_ALGORITHM_CONTAINS_SUBRANGE_HPP
#include <utility>
#include <concepts/concepts.hpp>
#include <range/v3/algorithm/search.hpp>
#include <range/v3/detail/config.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
/// `contains_subrange` is a search-based algorithm that checks whether or
/// not a given "needle" range is a subrange of a "haystack" range.
///
/// Example usage:
/// ```cpp
/// auto const haystack = std::vector{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
/// auto const needle = std::vector{3, 4, 5};
/// assert(ranges::contains(haystack, needle));
/// assert(ranges::contains(haystack, needle, ranges::less));
///
/// auto const not_a_needle = std::vector{4, 5, 3};
/// assert(not ranges::contains(haystack, not_a_needle));
/// ```
///
/// The interface supports both iterator-sentinel pairs and range objects.
/// Due to multi-pass iteration, this algorithm requires both ranges to be
/// forward ranges, and the elements' projections need to be comparable when
/// using the predicate.
RANGES_FUNC_BEGIN(contains_subrange)
/// \brief function template \c contains
template(typename I1, typename S1, typename I2, typename S2,
typename Pred = equal_to,
typename Proj1 = identity, typename Proj2 = identity)(
/// \pre
requires forward_iterator<I1> AND sentinel_for<S1, I1> AND
forward_iterator<I2> AND sentinel_for<S2, I2> AND
indirectly_comparable<I1, I2, Pred, Proj1, Proj2>)
constexpr bool RANGES_FUNC(contains)(I1 first1, S1 last1,
I2 first2, S2 last2,
Pred pred = {},
Proj1 proj1 = {},
Proj2 proj2 = {})
{
return first2 == last2 ||
ranges::search(first1, last1, first2, last2, pred, proj1, proj2).empty() == false;
}
/// \overload
template(typename Rng1, typename Rng2, typename Pred = equal_to,
typename Proj1 = identity, typename Proj2 = identity)(
/// \pre
requires forward_range<Rng1> AND forward_range<Rng2> AND
indirectly_comparable<iterator_t<Rng1>, iterator_t<Rng2>, Pred, Proj1, Proj2>)
constexpr bool RANGES_FUNC(contains)(Rng1 && rng1, Rng2 && rng2,
Pred pred = {},
Proj1 proj1 = {},
Proj2 proj2 = {})
{
return (*this)(ranges::begin(rng1), ranges::end(rng1),
ranges::begin(rng2), ranges::end(rng2),
std::move(pred), std::move(proj1), std::move(proj2));
}
RANGES_FUNC_END(contains_subrange)
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif // RANGES_V3_ALGORITHM_CONTAINS_SUBRANGE_HPP
|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/unstable_remove_if.hpp | /// \file
// Range v3 library
//
// Copyright Andrey Diduh 2019
// Copyright Casey Carter 2019
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_UNSTABLE_REMOVE_IF_HPP
#define RANGES_V3_ALGORITHM_UNSTABLE_REMOVE_IF_HPP
#include <functional>
#include <utility>
#include <concepts/concepts.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/find_if.hpp>
#include <range/v3/algorithm/find_if_not.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/reverse_iterator.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/utility/move.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
/// unstable_remove have O(1) complexity for each element remove, unlike remove O(n)
/// [for worst case]. Each erased element overwritten (moved in) with last one.
/// unstable_remove_if does not preserve relative element order.
RANGES_FUNC_BEGIN(unstable_remove_if)
/// \brief function template \c unstable_remove_if
template(typename I, typename C, typename P = identity)(
requires bidirectional_iterator<I> AND permutable<I> AND
indirect_unary_predicate<C, projected<I, P>>)
constexpr I RANGES_FUNC(unstable_remove_if)(I first, I last, C pred, P proj = {})
{
while(true)
{
first = find_if(std::move(first), last, ranges::ref(pred), ranges::ref(proj));
if(first == last)
return first;
last = next(find_if_not(make_reverse_iterator(std::move(last)),
make_reverse_iterator(next(first)),
ranges::ref(pred),
ranges::ref(proj)))
.base();
if(first == last)
return first;
*first = iter_move(last);
// discussion here: https://github.com/ericniebler/range-v3/issues/988
++first;
}
}
/// \overload
template(typename Rng, typename C, typename P = identity)(
requires bidirectional_range<Rng> AND common_range<Rng> AND
permutable<iterator_t<Rng>> AND
indirect_unary_predicate<C, projected<iterator_t<Rng>, P>>)
constexpr borrowed_iterator_t<Rng> //
RANGES_FUNC(unstable_remove_if)(Rng && rng, C pred, P proj = P{}) //
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(unstable_remove_if)
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif // RANGES_V3_ALGORITHM_UNSTABLE_REMOVE_IF_HPP
|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/remove_copy.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_REMOVE_COPY_HPP
#define RANGES_V3_ALGORITHM_REMOVE_COPY_HPP
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I, typename O>
using remove_copy_result = detail::in_out_result<I, O>;
RANGES_FUNC_BEGIN(remove_copy)
/// \brief function template \c remove_copy
template(typename I, typename S, typename O, typename T, typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
weakly_incrementable<O> AND
indirect_relation<equal_to, projected<I, P>, T const *> AND
indirectly_copyable<I, O>)
constexpr remove_copy_result<I, O> RANGES_FUNC(remove_copy)(
I first, S last, O out, T const & val, P proj = P{}) //
{
for(; first != last; ++first)
{
auto && x = *first;
if(!(invoke(proj, x) == val))
{
*out = (decltype(x) &&)x;
++out;
}
}
return {first, out};
}
/// \overload
template(typename Rng, typename O, typename T, typename P = identity)(
requires input_range<Rng> AND weakly_incrementable<O> AND
indirect_relation<equal_to, projected<iterator_t<Rng>, P>, T const *> AND
indirectly_copyable<iterator_t<Rng>, O>)
constexpr remove_copy_result<borrowed_iterator_t<Rng>, O> //
RANGES_FUNC(remove_copy)(Rng && rng, O out, T const & val, P proj = P{}) //
{
return (*this)(begin(rng), end(rng), std::move(out), val, std::move(proj));
}
RANGES_FUNC_END(remove_copy)
namespace cpp20
{
using ranges::remove_copy;
using ranges::remove_copy_result;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/adjacent_find.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_ADJACENT_FIND_HPP
#define RANGES_V3_ALGORITHM_ADJACENT_FIND_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(adjacent_find)
/// \brief function template \c adjacent_find
///
/// range-based version of the \c adjacent_find std algorithm
///
/// \pre `Rng` is a model of the `range` concept
/// \pre `C` is a model of the `BinaryPredicate` concept
template(typename I, typename S, typename C = equal_to, typename P = identity)(
requires forward_iterator<I> AND sentinel_for<S, I> AND
indirect_relation<C, projected<I, P>>)
constexpr I RANGES_FUNC(adjacent_find)(I first, S last, C pred = C{}, P proj = P{})
{
if(first == last)
return first;
auto inext = first;
for(; ++inext != last; first = inext)
if(invoke(pred, invoke(proj, *first), invoke(proj, *inext)))
return first;
return inext;
}
/// \overload
template(typename Rng, typename C = equal_to, typename P = identity)(
requires forward_range<Rng> AND
indirect_relation<C, projected<iterator_t<Rng>, P>>)
constexpr borrowed_iterator_t<Rng> //
RANGES_FUNC(adjacent_find)(Rng && rng, C pred = C{}, P proj = P{}) //
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(adjacent_find)
namespace cpp20
{
using ranges::adjacent_find;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif // RANGE_ALGORITHM_ADJACENT_FIND_HPP
|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/tagspec.hpp | // Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#ifndef RANGES_V3_ALGORITHM_TAGSPEC_HPP
#define RANGES_V3_ALGORITHM_TAGSPEC_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/utility/tagged_pair.hpp>
RANGES_DEPRECATED_HEADER(
"This file is deprecated. Please discontinue using the tag types defined here and "
"define your own.")
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \cond
RANGES_DEFINE_TAG_SPECIFIER(in)
RANGES_DEFINE_TAG_SPECIFIER(in1)
RANGES_DEFINE_TAG_SPECIFIER(in2)
RANGES_DEFINE_TAG_SPECIFIER(out)
RANGES_DEFINE_TAG_SPECIFIER(out1)
RANGES_DEFINE_TAG_SPECIFIER(out2)
RANGES_DEFINE_TAG_SPECIFIER(fun)
RANGES_DEFINE_TAG_SPECIFIER(min)
RANGES_DEFINE_TAG_SPECIFIER(max)
RANGES_DEFINE_TAG_SPECIFIER(begin)
RANGES_DEFINE_TAG_SPECIFIER(end)
RANGES_DEFINE_TAG_SPECIFIER(current)
RANGES_DEFINE_TAG_SPECIFIER(engine)
RANGES_DEFINE_TAG_SPECIFIER(range)
RANGES_DEFINE_TAG_SPECIFIER(size)
RANGES_DEFINE_TAG_SPECIFIER(first)
RANGES_DEFINE_TAG_SPECIFIER(second)
/// \endcond
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/rotate.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef RANGES_V3_ALGORITHM_ROTATE_HPP
#define RANGES_V3_ALGORITHM_ROTATE_HPP
#include <type_traits>
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/move.hpp>
#include <range/v3/algorithm/move_backward.hpp>
#include <range/v3/algorithm/swap_ranges.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/move.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/utility/swap.hpp>
#include <range/v3/view/subrange.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
/// \cond
namespace detail
{
template<typename I> // Forward
constexpr subrange<I> rotate_left(I first, I last)
{
iter_value_t<I> tmp = iter_move(first);
I lm1 = ranges::move(next(first), last, first).out;
*lm1 = std::move(tmp);
return {lm1, last};
}
template<typename I> // Bidirectional
constexpr subrange<I> rotate_right(I first, I last)
{
I lm1 = prev(last);
iter_value_t<I> tmp = iter_move(lm1);
I fp1 = move_backward(first, lm1, last).out;
*first = std::move(tmp);
return {fp1, last};
}
template<typename I, typename S> // Forward
constexpr subrange<I> rotate_forward(I first, I middle, S last)
{
I i = middle;
while(true)
{
ranges::iter_swap(first, i);
++first;
if(++i == last)
break;
if(first == middle)
middle = i;
}
I r = first;
if(first != middle)
{
I j = middle;
while(true)
{
ranges::iter_swap(first, j);
++first;
if(++j == last)
{
if(first == middle)
break;
j = middle;
}
else if(first == middle)
middle = j;
}
}
return {r, i};
}
template<typename D>
constexpr D gcd(D x, D y)
{
do
{
D t = x % y;
x = y;
y = t;
} while(y);
return x;
}
template<typename I> // Random
constexpr subrange<I> rotate_gcd(I first, I middle, I last)
{
auto const m1 = middle - first;
auto const m2 = last - middle;
if(m1 == m2)
{
swap_ranges(first, middle, middle);
return {middle, last};
}
auto const g = detail::gcd(m1, m2);
for(I p = first + g; p != first;)
{
iter_value_t<I> t = iter_move(--p);
I p1 = p;
I p2 = p1 + m1;
do
{
*p1 = iter_move(p2);
p1 = p2;
auto const d = last - p2;
if(m1 < d)
p2 += m1;
else
p2 = first + (m1 - d);
} while(p2 != p);
*p1 = std::move(t);
}
return {first + m2, last};
}
template<typename I, typename S>
constexpr subrange<I> rotate_(I first, I middle, S last, std::forward_iterator_tag)
{
return detail::rotate_forward(first, middle, last);
}
template<typename I>
constexpr subrange<I> rotate_(I first, I middle, I last, std::forward_iterator_tag)
{
using value_type = iter_value_t<I>;
if(detail::is_trivially_move_assignable_v<value_type>)
{
if(next(first) == middle)
return detail::rotate_left(first, last);
}
return detail::rotate_forward(first, middle, last);
}
template<typename I>
constexpr subrange<I> rotate_(I first, I middle, I last, std::bidirectional_iterator_tag)
{
using value_type = iter_value_t<I>;
if(detail::is_trivially_move_assignable_v<value_type>)
{
if(next(first) == middle)
return detail::rotate_left(first, last);
if(next(middle) == last)
return detail::rotate_right(first, last);
}
return detail::rotate_forward(first, middle, last);
}
template<typename I>
constexpr subrange<I> rotate_(I first, I middle, I last, std::random_access_iterator_tag)
{
using value_type = iter_value_t<I>;
if(detail::is_trivially_move_assignable_v<value_type>)
{
if(next(first) == middle)
return detail::rotate_left(first, last);
if(next(middle) == last)
return detail::rotate_right(first, last);
return detail::rotate_gcd(first, middle, last);
}
return detail::rotate_forward(first, middle, last);
}
} // namespace detail
/// \endcond
RANGES_FUNC_BEGIN(rotate)
/// \brief function template \c rotate
template(typename I, typename S)(
requires permutable<I> AND sentinel_for<S, I>)
constexpr subrange<I> RANGES_FUNC(rotate)(I first, I middle, S last) //
{
if(first == middle)
{
first = ranges::next(std::move(first), last);
return {first, first};
}
if(middle == last)
{
return {first, middle};
}
return detail::rotate_(first, middle, last, iterator_tag_of<I>{});
}
/// \overload
template(typename Rng, typename I = iterator_t<Rng>)(
requires range<Rng> AND permutable<I>)
constexpr borrowed_subrange_t<Rng> RANGES_FUNC(rotate)(Rng && rng, I middle) //
{
return (*this)(begin(rng), std::move(middle), end(rng));
}
RANGES_FUNC_END(rotate)
namespace cpp20
{
using ranges::rotate;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/fill_n.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_FILL_N_HPP
#define RANGES_V3_ALGORITHM_FILL_N_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(fill_n)
/// \brief function template \c equal
template(typename O, typename V)(
requires output_iterator<O, V const &>)
constexpr O RANGES_FUNC(fill_n)(O first, iter_difference_t<O> n, V const & val)
{
RANGES_EXPECT(n >= 0);
auto norig = n;
auto b = uncounted(first);
for(; n != 0; ++b, --n)
*b = val;
return recounted(first, b, norig);
}
RANGES_FUNC_END(fill_n)
namespace cpp20
{
using ranges::fill_n;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/shuffle.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_SHUFFLE_HPP
#define RANGES_V3_ALGORITHM_SHUFFLE_HPP
#include <cstdint>
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/random.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/utility/swap.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(shuffle)
/// \brief function template \c shuffle
template(typename I, typename S, typename Gen = detail::default_random_engine &)(
requires random_access_iterator<I> AND sentinel_for<S, I> AND
permutable<I> AND
uniform_random_bit_generator<std::remove_reference_t<Gen>> AND
convertible_to<invoke_result_t<Gen &>, iter_difference_t<I>>)
I RANGES_FUNC(shuffle)(I const first,
S const last,
Gen && gen = detail::get_random_engine()) //
{
auto mid = first;
if(mid == last)
return mid;
using D1 = iter_difference_t<I>;
using D2 =
meta::conditional_t<std::is_integral<D1>::value, D1, std::ptrdiff_t>;
std::uniform_int_distribution<D2> uid{};
using param_t = typename decltype(uid)::param_type;
while(++mid != last)
{
RANGES_ENSURE(mid - first <= PTRDIFF_MAX);
if(auto const i = uid(gen, param_t{0, D2(mid - first)}))
ranges::iter_swap(mid - i, mid);
}
return mid;
}
/// \overload
template(typename Rng, typename Gen = detail::default_random_engine &)(
requires random_access_range<Rng> AND permutable<iterator_t<Rng>> AND
uniform_random_bit_generator<std::remove_reference_t<Gen>> AND
convertible_to<invoke_result_t<Gen &>,
iter_difference_t<iterator_t<Rng>>>)
borrowed_iterator_t<Rng> //
RANGES_FUNC(shuffle)(Rng && rng, Gen && rand = detail::get_random_engine()) //
{
return (*this)(begin(rng), end(rng), static_cast<Gen &&>(rand));
}
RANGES_FUNC_END(shuffle)
namespace cpp20
{
using ranges::shuffle;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/copy_n.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_COPY_N_HPP
#define RANGES_V3_ALGORITHM_COPY_N_HPP
#include <functional>
#include <tuple>
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I, typename O>
using copy_n_result = detail::in_out_result<I, O>;
RANGES_FUNC_BEGIN(copy_n)
/// \brief function template \c copy_n
template(typename I, typename O, typename P = identity)(
requires input_iterator<I> AND weakly_incrementable<O> AND
indirectly_copyable<I, O>)
constexpr copy_n_result<I, O> RANGES_FUNC(copy_n)(I first, iter_difference_t<I> n, O out)
{
RANGES_EXPECT(0 <= n);
auto norig = n;
auto b = uncounted(first);
for(; n != 0; ++b, ++out, --n)
*out = *b;
return {recounted(first, b, norig), out};
}
RANGES_FUNC_END(copy_n)
namespace cpp20
{
using ranges::copy_n;
using ranges::copy_n_result;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/max_element.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_MAX_ELEMENT_HPP
#define RANGES_V3_ALGORITHM_MAX_ELEMENT_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(max_element)
/// \brief function template \c max_element
template(typename I, typename S, typename C = less, typename P = identity)(
requires forward_iterator<I> AND sentinel_for<S, I> AND
indirect_strict_weak_order<C, projected<I, P>>)
constexpr I RANGES_FUNC(max_element)(I first, S last, C pred = C{}, P proj = P{})
{
if(first != last)
for(auto tmp = next(first); tmp != last; ++tmp)
if(invoke(pred, invoke(proj, *first), invoke(proj, *tmp)))
first = tmp;
return first;
}
/// \overload
template(typename Rng, typename C = less, typename P = identity)(
requires forward_range<Rng> AND
indirect_strict_weak_order<C, projected<iterator_t<Rng>, P>>)
constexpr borrowed_iterator_t<Rng> //
RANGES_FUNC(max_element)(Rng && rng, C pred = C{}, P proj = P{})
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(max_element)
namespace cpp20
{
using ranges::max_element;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/move_backward.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_MOVE_BACKWARD_HPP
#define RANGES_V3_ALGORITHM_MOVE_BACKWARD_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I, typename O>
using move_backward_result = detail::in_out_result<I, O>;
RANGES_FUNC_BEGIN(move_backward)
/// \brief function template \c move_backward
template(typename I, typename S, typename O)(
requires bidirectional_iterator<I> AND sentinel_for<S, I> AND
bidirectional_iterator<O> AND indirectly_movable<I, O>)
constexpr move_backward_result<I, O> RANGES_FUNC(move_backward)(I first, S end_, O out) //
{
I i = ranges::next(first, end_), last = i;
while(first != i)
*--out = iter_move(--i);
return {last, out};
}
/// \overload
template(typename Rng, typename O)(
requires bidirectional_range<Rng> AND bidirectional_iterator<O> AND
indirectly_movable<iterator_t<Rng>, O>)
constexpr move_backward_result<borrowed_iterator_t<Rng>, O> //
RANGES_FUNC(move_backward)(Rng && rng, O out) //
{
return (*this)(begin(rng), end(rng), std::move(out));
}
RANGES_FUNC_END(move_backward)
namespace cpp20
{
using ranges::move_backward;
using ranges::move_backward_result;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/partition_copy.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_PARTITION_COPY_HPP
#define RANGES_V3_ALGORITHM_PARTITION_COPY_HPP
#include <tuple>
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
template<typename I, typename O0, typename O1>
using partition_copy_result = detail::in_out1_out2_result<I, O0, O1>;
RANGES_FUNC_BEGIN(partition_copy)
/// \brief function template \c partition_copy
template(typename I,
typename S,
typename O0,
typename O1,
typename C,
typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
weakly_incrementable<O0> AND weakly_incrementable<O1> AND
indirectly_copyable<I, O0> AND indirectly_copyable<I, O1> AND
indirect_unary_predicate<C, projected<I, P>>)
constexpr partition_copy_result<I, O0, O1> RANGES_FUNC(partition_copy)(
I first, S last, O0 o0, O1 o1, C pred, P proj = P{})
{
for(; first != last; ++first)
{
auto && x = *first;
if(invoke(pred, invoke(proj, x)))
{
*o0 = (decltype(x) &&)x;
++o0;
}
else
{
*o1 = (decltype(x) &&)x;
++o1;
}
}
return {first, o0, o1};
}
/// \overload
template(typename Rng,
typename O0,
typename O1,
typename C,
typename P = identity)(
requires input_range<Rng> AND weakly_incrementable<O0> AND
weakly_incrementable<O1> AND indirectly_copyable<iterator_t<Rng>, O0> AND
indirectly_copyable<iterator_t<Rng>, O1> AND
indirect_unary_predicate<C, projected<iterator_t<Rng>, P>>)
constexpr partition_copy_result<borrowed_iterator_t<Rng>, O0, O1> //
RANGES_FUNC(partition_copy)(Rng && rng, O0 o0, O1 o1, C pred, P proj = P{})
{
return (*this)(begin(rng),
end(rng),
std::move(o0),
std::move(o1),
std::move(pred),
std::move(proj));
}
RANGES_FUNC_END(partition_copy)
namespace cpp20
{
using ranges::partition_copy;
using ranges::partition_copy_result;
} // namespace cpp20
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/remove.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_REMOVE_HPP
#define RANGES_V3_ALGORITHM_REMOVE_HPP
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/find.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(remove)
/// \brief function template \c remove
template(typename I, typename S, typename T, typename P = identity)(
requires permutable<I> AND sentinel_for<S, I> AND
indirect_relation<equal_to, projected<I, P>, T const *>)
constexpr I RANGES_FUNC(remove)(I first, S last, T const & val, P proj = P{})
{
first = find(std::move(first), last, val, ranges::ref(proj));
if(first != last)
{
for(I i = next(first); i != last; ++i)
{
if(!(invoke(proj, *i) == val))
{
*first = iter_move(i);
++first;
}
}
}
return first;
}
/// \overload
template(typename Rng, typename T, typename P = identity)(
requires forward_range<Rng> AND permutable<iterator_t<Rng>> AND
indirect_relation<equal_to, projected<iterator_t<Rng>, P>, T const *>)
constexpr borrowed_iterator_t<Rng> //
RANGES_FUNC(remove)(Rng && rng, T const & val, P proj = P{})
{
return (*this)(begin(rng), end(rng), val, std::move(proj));
}
RANGES_FUNC_END(remove)
namespace cpp20
{
using ranges::remove;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/all_of.hpp | /// \file
// Range v3 library
//
// Copyright Andrew Sutton 2014
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_ALL_OF_HPP
#define RANGES_V3_ALGORITHM_ALL_OF_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(all_of)
/// \brief function template \c all_of
template(typename I, typename S, typename F, typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
indirect_unary_predicate<F, projected<I, P>>)
constexpr bool RANGES_FUNC(all_of)(I first, S last, F pred, P proj = P{}) //
{
for(; first != last; ++first)
if(!invoke(pred, invoke(proj, *first)))
break;
return first == last;
}
/// \overload
template(typename Rng, typename F, typename P = identity)(
requires input_range<Rng> AND
indirect_unary_predicate<F, projected<iterator_t<Rng>, P>>)
constexpr bool RANGES_FUNC(all_of)(Rng && rng, F pred, P proj = P{}) //
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(all_of)
namespace cpp20
{
using ranges::all_of;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/stable_partition.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
//===-------------------------- algorithm ---------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef RANGES_V3_ALGORITHM_STABLE_PARTITION_HPP
#define RANGES_V3_ALGORITHM_STABLE_PARTITION_HPP
#include <functional>
#include <memory>
#include <type_traits>
#include <meta/meta.hpp>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/move.hpp>
#include <range/v3/algorithm/partition_copy.hpp>
#include <range/v3/algorithm/rotate.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/move_iterators.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/memory.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/utility/swap.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
/// \cond
namespace detail
{
template<typename I, typename C, typename P, typename D, typename Pair>
I stable_partition_impl(I first, I last, C pred, P proj, D len, Pair const p,
std::forward_iterator_tag fi)
{
// *first is known to be false
// len >= 1
if(len == 1)
return first;
if(len == 2)
{
I tmp = first;
if(invoke(pred, invoke(proj, *++tmp)))
{
ranges::iter_swap(first, tmp);
return tmp;
}
return first;
}
if(len <= p.second)
{ // The buffer is big enough to use
// Move the falses into the temporary buffer, and the trues to the front
// of the line Update first to always point to the last of the trues
auto tmpbuf = make_raw_buffer(p.first);
auto buf = tmpbuf.begin();
*buf = iter_move(first);
++buf;
auto res = partition_copy(make_move_iterator(next(first)),
make_move_sentinel(last),
first,
buf,
std::ref(pred),
std::ref(proj));
// All trues now at start of range, all falses in buffer
// Move falses back into range, but don't mess up first which points to
// first false
ranges::move(p.first, res.out2.base().base(), res.out1);
// h destructs moved-from values out of the temp buffer, but doesn't
// deallocate buffer
return res.out1;
}
// Else not enough buffer, do in place
// len >= 3
D half = len / 2; // half >= 2
I middle = next(first, half);
// recurse on [first, middle), *first know to be false
// F?????????????????
// f m l
I begin_false =
detail::stable_partition_impl(first, middle, pred, proj, half, p, fi);
// TTTFFFFF??????????
// f ff m l
// recurse on [middle, last], except increase middle until *(middle) is false,
// *last know to be true
I m1 = middle;
D len_half = len - half;
while(invoke(pred, invoke(proj, *m1)))
{
if(++m1 == last)
return ranges::rotate(begin_false, middle, last).begin();
--len_half;
}
// TTTFFFFFTTTF??????
// f ff m m1 l
I end_false =
detail::stable_partition_impl(m1, last, pred, proj, len_half, p, fi);
// TTTFFFFFTTTTTFFFFF
// f ff m sf l
return ranges::rotate(begin_false, middle, end_false).begin();
// TTTTTTTTFFFFFFFFFF
// |
}
template<typename I, typename S, typename C, typename P>
I stable_partition_impl(I first, S last, C pred, P proj,
std::forward_iterator_tag fi)
{
using difference_type = iter_difference_t<I>;
difference_type const alloc_limit = 3; // might want to make this a function
// of trivial assignment.
// Either prove all true and return first or point to first false
while(true)
{
if(first == last)
return first;
if(!invoke(pred, invoke(proj, *first)))
break;
++first;
}
// We now have a reduced range [first, last)
// *first is known to be false
using value_type = iter_value_t<I>;
auto len_end = enumerate(first, last);
auto p = len_end.first >= alloc_limit
? detail::get_temporary_buffer<value_type>(len_end.first)
: detail::value_init{};
std::unique_ptr<value_type, detail::return_temporary_buffer> const h{p.first};
return detail::stable_partition_impl(
first, len_end.second, pred, proj, len_end.first, p, fi);
}
template<typename I, typename C, typename P, typename D, typename Pair>
I stable_partition_impl(I first, I last, C pred, P proj, D len, Pair p,
std::bidirectional_iterator_tag bi)
{
// *first is known to be false
// *last is known to be true
// len >= 2
if(len == 2)
{
ranges::iter_swap(first, last);
return last;
}
if(len == 3)
{
I tmp = first;
if(invoke(pred, invoke(proj, *++tmp)))
{
ranges::iter_swap(first, tmp);
ranges::iter_swap(tmp, last);
return last;
}
ranges::iter_swap(tmp, last);
ranges::iter_swap(first, tmp);
return tmp;
}
if(len <= p.second)
{ // The buffer is big enough to use
// Move the falses into the temporary buffer, and the trues to the front
// of the line Update first to always point to the last of the trues
auto tmpbuf = ranges::make_raw_buffer(p.first);
auto buf = tmpbuf.begin();
*buf = iter_move(first);
++buf;
auto res = partition_copy(make_move_iterator(next(first)),
make_move_sentinel(last),
first,
buf,
std::ref(pred),
std::ref(proj));
first = res.out1;
// move *last, known to be true
*first = iter_move(res.in);
++first;
// All trues now at start of range, all falses in buffer
// Move falses back into range, but don't mess up first which points to
// first false
ranges::move(p.first, res.out2.base().base(), first);
// h destructs moved-from values out of the temp buffer, but doesn't
// deallocate buffer
return first;
}
// Else not enough buffer, do in place
// len >= 4
I middle = first;
D half = len / 2; // half >= 2
advance(middle, half);
// recurse on [first, middle-1], except reduce middle-1 until *(middle-1) is
// true, *first know to be false F????????????????T f m l
I m1 = middle;
I begin_false = first;
D len_half = half;
while(!invoke(pred, invoke(proj, *--m1)))
{
if(m1 == first)
goto first_half_done;
--len_half;
}
// F???TFFF?????????T
// f m1 m l
begin_false =
detail::stable_partition_impl(first, m1, pred, proj, len_half, p, bi);
first_half_done:
// TTTFFFFF?????????T
// f ff m l
// recurse on [middle, last], except increase middle until *(middle) is false,
// *last know to be true
m1 = middle;
len_half = len - half;
while(invoke(pred, invoke(proj, *m1)))
{
if(++m1 == last)
return ranges::rotate(begin_false, middle, ++last).begin();
--len_half;
}
// TTTFFFFFTTTF?????T
// f ff m m1 l
I end_false =
detail::stable_partition_impl(m1, last, pred, proj, len_half, p, bi);
// TTTFFFFFTTTTTFFFFF
// f ff m sf l
return ranges::rotate(begin_false, middle, end_false).begin();
// TTTTTTTTFFFFFFFFFF
// |
}
template<typename I, typename S, typename C, typename P>
I stable_partition_impl(I first, S end_, C pred, P proj,
std::bidirectional_iterator_tag bi)
{
using difference_type = iter_difference_t<I>;
using value_type = iter_value_t<I>;
difference_type const alloc_limit =
4; // might want to make this a function of trivial assignment
// Either prove all true and return first or point to first false
while(true)
{
if(first == end_)
return first;
if(!invoke(pred, invoke(proj, *first)))
break;
++first;
}
// first points to first false, everything prior to first is already set.
// Either prove [first, last) is all false and return first, or point last to
// last true
I last = ranges::next(first, end_);
do
{
if(first == --last)
return first;
} while(!invoke(pred, invoke(proj, *last)));
// We now have a reduced range [first, last]
// *first is known to be false
// *last is known to be true
// len >= 2
auto len = distance(first, last) + 1;
auto p = len >= alloc_limit ? detail::get_temporary_buffer<value_type>(len)
: detail::value_init{};
std::unique_ptr<value_type, detail::return_temporary_buffer> const h{p.first};
return detail::stable_partition_impl(first, last, pred, proj, len, p, bi);
}
} // namespace detail
/// \endcond
RANGES_FUNC_BEGIN(stable_partition)
/// \brief function template \c stable_partition
template(typename I, typename S, typename C, typename P = identity)(
requires bidirectional_iterator<I> AND sentinel_for<S, I> AND
indirect_unary_predicate<C, projected<I, P>> AND permutable<I>)
I RANGES_FUNC(stable_partition)(I first, S last, C pred, P proj = P{})
{
return detail::stable_partition_impl(std::move(first),
std::move(last),
std::ref(pred),
std::ref(proj),
iterator_tag_of<I>());
}
// BUGBUG Can this be optimized if Rng has O1 size?
/// \overload
template(typename Rng, typename C, typename P = identity)(
requires bidirectional_range<Rng> AND
indirect_unary_predicate<C, projected<iterator_t<Rng>, P>> AND
permutable<iterator_t<Rng>>)
borrowed_iterator_t<Rng> //
RANGES_FUNC(stable_partition)(Rng && rng, C pred, P proj = P{}) //
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(stable_partition)
namespace cpp20
{
using ranges::stable_partition;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/count.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_COUNT_HPP
#define RANGES_V3_ALGORITHM_COUNT_HPP
#include <utility>
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-algorithms
/// @{
RANGES_FUNC_BEGIN(count)
/// \brief function template \c count
template(typename I, typename S, typename V, typename P = identity)(
requires input_iterator<I> AND sentinel_for<S, I> AND
indirect_relation<equal_to, projected<I, P>, V const *>)
constexpr iter_difference_t<I> //
RANGES_FUNC(count)(I first, S last, V const & val, P proj = P{})
{
iter_difference_t<I> n = 0;
for(; first != last; ++first)
if(invoke(proj, *first) == val)
++n;
return n;
}
/// \overload
template(typename Rng, typename V, typename P = identity)(
requires input_range<Rng> AND
indirect_relation<equal_to, projected<iterator_t<Rng>, P>, V const *>)
constexpr iter_difference_t<iterator_t<Rng>> //
RANGES_FUNC(count)(Rng && rng, V const & val, P proj = P{})
{
return (*this)(begin(rng), end(rng), val, std::move(proj));
}
RANGES_FUNC_END(count)
namespace cpp20
{
using ranges::count;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3 | repos/range-v3/include/range/v3/algorithm/sort.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright (c) 1994
// Hewlett-Packard Company
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without fee,
// provided that the above copyright notice appear in all copies and
// that both that copyright notice and this permission notice appear
// in supporting documentation. Hewlett-Packard Company makes no
// representations about the suitability of this software for any
// purpose. It is provided "as is" without express or implied warranty.
//
// Copyright (c) 1996
// Silicon Graphics Computer Systems, Inc.
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without fee,
// provided that the above copyright notice appear in all copies and
// that both that copyright notice and this permission notice appear
// in supporting documentation. Silicon Graphics makes no
// representations about the suitability of this software for any
// purpose. It is provided "as is" without express or implied warranty.
//
#ifndef RANGES_V3_ALGORITHM_SORT_HPP
#define RANGES_V3_ALGORITHM_SORT_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/heap_algorithm.hpp>
#include <range/v3/algorithm/move_backward.hpp>
#include <range/v3/algorithm/partial_sort.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/dangling.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \cond
namespace detail
{
template<typename I, typename C, typename P>
inline constexpr I unguarded_partition(I first, I last, C & pred, P & proj)
{
I mid = first + (last - first) / 2, penultimate = ranges::prev(last);
auto &&x = *first, &&y = *mid, &&z = *penultimate;
auto &&a = invoke(proj, (decltype(x) &&)x),
&&b = invoke(proj, (decltype(y) &&)y),
&&c = invoke(proj, (decltype(z) &&)z);
// Find the median:
I pivot_pnt =
invoke(pred, a, b)
? (invoke(pred, b, c) ? mid
: (invoke(pred, a, c) ? penultimate : first))
: (invoke(pred, a, c) ? first
: (invoke(pred, b, c) ? penultimate : mid));
// Do the partition:
while(true)
{
auto && v = *pivot_pnt;
auto && pivot = invoke(proj, (decltype(v) &&)v);
while(invoke(pred, invoke(proj, *first), pivot))
++first;
--last;
while(invoke(pred, pivot, invoke(proj, *last)))
--last;
if(!(first < last))
return first;
ranges::iter_swap(first, last);
pivot_pnt =
pivot_pnt == first ? last : (pivot_pnt == last ? first : pivot_pnt);
++first;
}
}
template<typename I, typename C, typename P>
inline constexpr void unguarded_linear_insert(I last,
iter_value_t<I> val,
C & pred,
P & proj)
{
I next_ = prev(last);
while(invoke(pred, invoke(proj, val), invoke(proj, *next_)))
{
*last = iter_move(next_);
last = next_;
--next_;
}
*last = std::move(val);
}
template<typename I, typename C, typename P>
inline constexpr void linear_insert(I first, I last, C & pred, P & proj)
{
iter_value_t<I> val = iter_move(last);
if(invoke(pred, invoke(proj, val), invoke(proj, *first)))
{
move_backward(first, last, last + 1);
*first = std::move(val);
}
else
detail::unguarded_linear_insert(last, std::move(val), pred, proj);
}
template<typename I, typename C, typename P>
inline constexpr void insertion_sort(I first, I last, C & pred, P & proj)
{
if(first == last)
return;
for(I i = next(first); i != last; ++i)
detail::linear_insert(first, i, pred, proj);
}
template<typename I, typename C, typename P>
inline constexpr void unguarded_insertion_sort(I first, I last, C & pred, P & proj)
{
for(I i = first; i != last; ++i)
detail::unguarded_linear_insert(i, iter_move(i), pred, proj);
}
constexpr int introsort_threshold()
{
return 16;
}
template<typename I, typename C, typename P>
inline constexpr void final_insertion_sort(I first, I last, C & pred, P & proj)
{
if(last - first > detail::introsort_threshold())
{
detail::insertion_sort(
first, first + detail::introsort_threshold(), pred, proj);
detail::unguarded_insertion_sort(
first + detail::introsort_threshold(), last, pred, proj);
}
else
detail::insertion_sort(first, last, pred, proj);
}
template<typename Size>
inline constexpr Size log2(Size n)
{
Size k = 0;
for(; n != 1; n >>= 1)
++k;
return k;
}
template<typename I, typename Size, typename C, typename P>
inline constexpr void introsort_loop(I first, I last, Size depth_limit, C & pred, P & proj)
{
while(last - first > detail::introsort_threshold())
{
if(depth_limit == 0)
return partial_sort(
first, last, last, std::ref(pred), std::ref(proj)),
void();
I cut = detail::unguarded_partition(first, last, pred, proj);
detail::introsort_loop(cut, last, --depth_limit, pred, proj);
last = cut;
}
}
} // namespace detail
/// \endcond
/// \addtogroup group-algorithms
/// @{
// Introsort: Quicksort to a certain depth, then Heapsort. Insertion
// sort below a certain threshold.
// TODO Forward iterators, like EoP?
RANGES_FUNC_BEGIN(sort)
/// \brief function template \c sort
template(typename I, typename S, typename C = less, typename P = identity)(
requires sortable<I, C, P> AND random_access_iterator<I> AND
sentinel_for<S, I>)
constexpr I RANGES_FUNC(sort)(I first, S end_, C pred = C{}, P proj = P{})
{
I last = ranges::next(first, std::move(end_));
if(first != last)
{
detail::introsort_loop(
first, last, detail::log2(last - first) * 2, pred, proj);
detail::final_insertion_sort(first, last, pred, proj);
}
return last;
}
/// \overload
template(typename Rng, typename C = less, typename P = identity)(
requires sortable<iterator_t<Rng>, C, P> AND random_access_range<Rng>)
constexpr borrowed_iterator_t<Rng> //
RANGES_FUNC(sort)(Rng && rng, C pred = C{}, P proj = P{}) //
{
return (*this)(begin(rng), end(rng), std::move(pred), std::move(proj));
}
RANGES_FUNC_END(sort)
namespace cpp20
{
using ranges::sort;
}
/// @}
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3/algorithm | repos/range-v3/include/range/v3/algorithm/aux_/merge_n_with_buffer.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright (c) 2009 Alexander Stepanov and Paul McJones
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without
// fee, provided that the above copyright notice appear in all copies
// and that both that copyright notice and this permission notice
// appear in supporting documentation. The authors make no
// representations about the suitability of this software for any
// purpose. It is provided "as is" without express or implied
// warranty.
//
// Algorithms from
// Elements of Programming
// by Alexander Stepanov and Paul McJones
// Addison-Wesley Professional, 2009
#ifndef RANGES_V3_ALGORITHM_AUX_MERGE_N_WITH_BUFFER_HPP
#define RANGES_V3_ALGORITHM_AUX_MERGE_N_WITH_BUFFER_HPP
#include <tuple>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/aux_/merge_n.hpp>
#include <range/v3/algorithm/copy_n.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
namespace aux
{
struct merge_n_with_buffer_fn
{
template(typename I, typename B, typename C = less, typename P = identity)(
requires same_as<iter_common_reference_t<I>,
iter_common_reference_t<B>> AND
indirectly_copyable<I, B> AND mergeable<B, I, I, C, P, P>)
I operator()(I begin0,
iter_difference_t<I> n0,
I begin1,
iter_difference_t<I> n1,
B buff,
C r = C{},
P p = P{}) const
{
copy_n(begin0, n0, buff);
return merge_n(buff, n0, begin1, n1, begin0, r, p, p).out;
}
};
RANGES_INLINE_VARIABLE(merge_n_with_buffer_fn, merge_n_with_buffer)
} // namespace aux
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3/algorithm | repos/range-v3/include/range/v3/algorithm/aux_/partition_point_n.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Casey Carter 2016
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_AUX_PARTITION_POINT_N_HPP
#define RANGES_V3_ALGORITHM_AUX_PARTITION_POINT_N_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
namespace aux
{
struct partition_point_n_fn
{
template(typename I, typename C, typename P = identity)(
requires forward_iterator<I> AND
indirect_unary_predicate<C, projected<I, P>>)
constexpr I operator()(I first,
iter_difference_t<I> d,
C pred,
P proj = P{}) const //
{
if(0 < d)
{
do
{
auto half = d / 2;
auto middle = next(uncounted(first), half);
if(invoke(pred, invoke(proj, *middle)))
{
first = recounted(first, std::move(++middle), half + 1);
d -= half + 1;
}
else
d = half;
} while(0 != d);
}
return first;
}
};
RANGES_INLINE_VARIABLE(partition_point_n_fn, partition_point_n)
} // namespace aux
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3/algorithm | repos/range-v3/include/range/v3/algorithm/aux_/equal_range_n.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_AUX_EQUAL_RANGE_N_HPP
#define RANGES_V3_ALGORITHM_AUX_EQUAL_RANGE_N_HPP
#include <functional>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/aux_/lower_bound_n.hpp>
#include <range/v3/algorithm/aux_/upper_bound_n.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/functional/reference_wrapper.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/view/subrange.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
namespace aux
{
struct equal_range_n_fn
{
template(typename I, typename V, typename R = less, typename P = identity)(
requires forward_iterator<I> AND
indirect_strict_weak_order<R, V const *, projected<I, P>>)
constexpr subrange<I> operator()(I first,
iter_difference_t<I> dist,
V const & val,
R pred = R{},
P proj = P{}) const
{
if(0 < dist)
{
do
{
auto half = dist / 2;
auto middle = ranges::next(first, half);
auto && v = *middle;
auto && pv = invoke(proj, (decltype(v) &&)v);
if(invoke(pred, pv, val))
{
first = std::move(++middle);
dist -= half + 1;
}
else if(invoke(pred, val, pv))
{
dist = half;
}
else
{
return {lower_bound_n(std::move(first),
half,
val,
ranges::ref(pred),
ranges::ref(proj)),
upper_bound_n(ranges::next(middle),
dist - (half + 1),
val,
ranges::ref(pred),
ranges::ref(proj))};
}
} while(0 != dist);
}
return {first, first};
}
};
RANGES_INLINE_VARIABLE(equal_range_n_fn, equal_range_n)
} // namespace aux
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3/algorithm | repos/range-v3/include/range/v3/algorithm/aux_/merge_n.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright (c) 2009 Alexander Stepanov and Paul McJones
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without
// fee, provided that the above copyright notice appear in all copies
// and that both that copyright notice and this permission notice
// appear in supporting documentation. The authors make no
// representations about the suitability of this software for any
// purpose. It is provided "as is" without express or implied
// warranty.
//
// Algorithms from
// Elements of Programming
// by Alexander Stepanov and Paul McJones
// Addison-Wesley Professional, 2009
#ifndef RANGES_V3_ALGORITHM_AUX_MERGE_N_HPP
#define RANGES_V3_ALGORITHM_AUX_MERGE_N_HPP
#include <tuple>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/copy_n.hpp>
#include <range/v3/algorithm/result_types.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
namespace aux
{
template<typename I0, typename I1, typename O>
using merge_n_result = detail::in1_in2_out_result<I0, I1, O>;
struct merge_n_fn
{
template(typename I0, typename I1, typename O, typename C = less,
typename P0 = identity, typename P1 = identity)(
requires mergeable<I0, I1, O, C, P0, P1>)
merge_n_result<I0, I1, O> operator()(I0 begin0,
iter_difference_t<I0> n0,
I1 begin1,
iter_difference_t<I1> n1,
O out,
C r = C{},
P0 p0 = P0{},
P1 p1 = P1{}) const
{
using T = merge_n_result<I0, I1, O>;
auto n0orig = n0;
auto n1orig = n1;
auto b0 = uncounted(begin0);
auto b1 = uncounted(begin1);
while(true)
{
if(0 == n0)
{
auto res = copy_n(b1, n1, out);
begin0 = recounted(begin0, b0, n0orig);
begin1 = recounted(begin1, res.in, n1orig);
return T{begin0, begin1, res.out};
}
if(0 == n1)
{
auto res = copy_n(b0, n0, out);
begin0 = recounted(begin0, res.in, n0orig);
begin1 = recounted(begin1, b1, n1orig);
return T{begin0, begin1, res.out};
}
if(invoke(r, invoke(p1, *b1), invoke(p0, *b0)))
{
*out = *b1;
++b1;
++out;
--n1;
}
else
{
*out = *b0;
++b0;
++out;
--n0;
}
}
}
};
RANGES_INLINE_VARIABLE(merge_n_fn, merge_n)
} // namespace aux
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3/algorithm | repos/range-v3/include/range/v3/algorithm/aux_/upper_bound_n.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Casey Carter 2016
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_AUX_UPPER_BOUND_N_HPP
#define RANGES_V3_ALGORITHM_AUX_UPPER_BOUND_N_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/aux_/partition_point_n.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \cond
namespace detail
{
// [&](auto&& i){ return !invoke(pred, val, i); }
template<typename Pred, typename Val>
struct upper_bound_predicate
{
Pred & pred_;
Val & val_;
template<typename T>
constexpr bool operator()(T && t) const
{
return !invoke(pred_, val_, static_cast<T &&>(t));
}
};
template<typename Pred, typename Val>
constexpr upper_bound_predicate<Pred, Val> make_upper_bound_predicate(Pred & pred,
Val & val)
{
return {pred, val};
}
} // namespace detail
/// \endcond
namespace aux
{
struct upper_bound_n_fn
{
/// \brief template function upper_bound
///
/// range-based version of the `upper_bound` std algorithm
///
/// \pre `Rng` is a model of the `range` concept
template(typename I, typename V, typename C = less, typename P = identity)(
requires forward_iterator<I> AND
indirect_strict_weak_order<C, V const *, projected<I, P>>)
constexpr I operator()(I first,
iter_difference_t<I> d,
V const & val,
C pred = C{},
P proj = P{}) const
{
return partition_point_n(std::move(first),
d,
detail::make_upper_bound_predicate(pred, val),
std::move(proj));
}
};
RANGES_INLINE_VARIABLE(upper_bound_n_fn, upper_bound_n)
} // namespace aux
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3/algorithm | repos/range-v3/include/range/v3/algorithm/aux_/sort_n_with_buffer.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Copyright (c) 2009 Alexander Stepanov and Paul McJones
//
// Permission to use, copy, modify, distribute and sell this software
// and its documentation for any purpose is hereby granted without
// fee, provided that the above copyright notice appear in all copies
// and that both that copyright notice and this permission notice
// appear in supporting documentation. The authors make no
// representations about the suitability of this software for any
// purpose. It is provided "as is" without express or implied
// warranty.
//
// Algorithms from
// Elements of Programming
// by Alexander Stepanov and Paul McJones
// Addison-Wesley Professional, 2009
#ifndef RANGES_V3_ALGORITHM_AUX_SORT_N_WITH_BUFFER_HPP
#define RANGES_V3_ALGORITHM_AUX_SORT_N_WITH_BUFFER_HPP
#include <tuple>
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/aux_/merge_n_with_buffer.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
namespace aux
{
struct sort_n_with_buffer_fn
{
template(typename I, typename B, typename C = less, typename P = identity)(
requires same_as<iter_common_reference_t<I>,
iter_common_reference_t<B>> AND
indirectly_copyable<I, B> AND mergeable<B, I, I, C, P, P>)
I operator()(I first, iter_difference_t<I> n, B buff, C r = C{}, P p = P{})
const
{
auto half = n / 2;
if(0 == half)
return next(first, n);
I m = (*this)(first, half, buff, r, p);
(*this)(m, n - half, buff, r, p);
return merge_n_with_buffer(first, half, m, n - half, buff, r, p);
}
};
RANGES_INLINE_VARIABLE(sort_n_with_buffer_fn, sort_n_with_buffer)
} // namespace aux
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include/range/v3/algorithm | repos/range-v3/include/range/v3/algorithm/aux_/lower_bound_n.hpp | /// \file
// Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Casey Carter 2016
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_ALGORITHM_AUX_LOWER_BOUND_N_HPP
#define RANGES_V3_ALGORITHM_AUX_LOWER_BOUND_N_HPP
#include <range/v3/range_fwd.hpp>
#include <range/v3/algorithm/aux_/partition_point_n.hpp>
#include <range/v3/functional/comparisons.hpp>
#include <range/v3/functional/identity.hpp>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/utility/static_const.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \cond
namespace detail
{
// [&](auto&& i){ return invoke(pred, i, val); }
template<typename Pred, typename Val>
struct lower_bound_predicate
{
Pred & pred_;
Val & val_;
template<typename T>
constexpr bool operator()(T && t) const
{
return invoke(pred_, static_cast<T &&>(t), val_);
}
};
template<typename Pred, typename Val>
constexpr lower_bound_predicate<Pred, Val> make_lower_bound_predicate(Pred & pred,
Val & val)
{
return {pred, val};
}
} // namespace detail
/// \endcond
namespace aux
{
struct lower_bound_n_fn
{
template(typename I, typename V, typename C = less, typename P = identity)(
requires forward_iterator<I> AND
indirect_strict_weak_order<C, V const *, projected<I, P>>)
constexpr I operator()(I first,
iter_difference_t<I> d,
V const & val,
C pred = C{},
P proj = P{}) const
{
return partition_point_n(std::move(first),
d,
detail::make_lower_bound_predicate(pred, val),
std::move(proj));
}
};
RANGES_INLINE_VARIABLE(lower_bound_n_fn, lower_bound_n)
} // namespace aux
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3/include | repos/range-v3/include/meta/meta_fwd.hpp | /// \file meta_fwd.hpp Forward declarations
//
// Meta library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/meta
//
#ifndef META_FWD_HPP
#define META_FWD_HPP
#include <type_traits>
#include <utility>
#ifdef __clang__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmissing-variable-declarations"
#endif
#define META_CXX_STD_14 201402L
#define META_CXX_STD_17 201703L
#if defined(_MSVC_LANG) && _MSVC_LANG > __cplusplus // Older clangs define _MSVC_LANG < __cplusplus
#define META_CXX_VER _MSVC_LANG
#else
#define META_CXX_VER __cplusplus
#endif
#if defined(__apple_build_version__) || defined(__clang__)
#if defined(__apple_build_version__) || (defined(__clang__) && __clang_major__ < 6)
#define META_WORKAROUND_LLVM_28385 // https://llvm.org/bugs/show_bug.cgi?id=28385
#endif
#elif defined(_MSC_VER)
#define META_HAS_MAKE_INTEGER_SEQ 1
#if _MSC_VER < 1920
#define META_WORKAROUND_MSVC_702792 // Bogus C4018 comparing constant expressions with dependent type
#define META_WORKAROUND_MSVC_703656 // ICE with pack expansion inside decltype in alias template
#endif
#if _MSC_VER < 1921
#define META_WORKAROUND_MSVC_756112 // fold expression + alias templates in template argument
#endif
#elif defined(__GNUC__)
#define META_WORKAROUND_GCC_86356 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86356
#if __GNUC__ < 8
#define META_WORKAROUND_GCC_UNKNOWN1 // Older GCCs don't like fold + debug + -march=native
#endif
#if __GNUC__ == 5 && __GNUC_MINOR__ == 1
#define META_WORKAROUND_GCC_66405 // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66405
#endif
#if __GNUC__ < 5
#define META_WORKAROUND_CWG_1558 // https://wg21.link/cwg1558
#endif
#endif
#ifndef META_CXX_VARIABLE_TEMPLATES
#ifdef __cpp_variable_templates
#define META_CXX_VARIABLE_TEMPLATES __cpp_variable_templates
#else
#define META_CXX_VARIABLE_TEMPLATES (META_CXX_VER >= META_CXX_STD_14)
#endif
#endif
#ifndef META_CXX_INLINE_VARIABLES
#ifdef __cpp_inline_variables
#define META_CXX_INLINE_VARIABLES __cpp_inline_variables
#else
#define META_CXX_INLINE_VARIABLES (META_CXX_VER >= META_CXX_STD_17)
#endif
#endif
#ifndef META_INLINE_VAR
#if META_CXX_INLINE_VARIABLES
#define META_INLINE_VAR inline
#else
#define META_INLINE_VAR
#endif
#endif
#ifndef META_CXX_INTEGER_SEQUENCE
#ifdef __cpp_lib_integer_sequence
#define META_CXX_INTEGER_SEQUENCE __cpp_lib_integer_sequence
#else
#define META_CXX_INTEGER_SEQUENCE (META_CXX_VER >= META_CXX_STD_14)
#endif
#endif
#ifndef META_HAS_MAKE_INTEGER_SEQ
#ifdef __has_builtin
#if __has_builtin(__make_integer_seq)
#define META_HAS_MAKE_INTEGER_SEQ 1
#endif
#endif
#endif
#ifndef META_HAS_MAKE_INTEGER_SEQ
#define META_HAS_MAKE_INTEGER_SEQ 0
#endif
#ifndef META_HAS_TYPE_PACK_ELEMENT
#ifdef __has_builtin
#if __has_builtin(__type_pack_element)
#define META_HAS_TYPE_PACK_ELEMENT 1
#endif
#endif
#endif
#ifndef META_HAS_TYPE_PACK_ELEMENT
#define META_HAS_TYPE_PACK_ELEMENT 0
#endif
#if !defined(META_DEPRECATED) && !defined(META_DISABLE_DEPRECATED_WARNINGS)
#if defined(__cpp_attribute_deprecated) || META_CXX_VER >= META_CXX_STD_14
#define META_DEPRECATED(...) [[deprecated(__VA_ARGS__)]]
#elif defined(__clang__) || defined(__GNUC__)
#define META_DEPRECATED(...) __attribute__((deprecated(__VA_ARGS__)))
#endif
#endif
#ifndef META_DEPRECATED
#define META_DEPRECATED(...)
#endif
#ifndef META_CXX_FOLD_EXPRESSIONS
#ifdef __cpp_fold_expressions
#define META_CXX_FOLD_EXPRESSIONS __cpp_fold_expressions
#else
#define META_CXX_FOLD_EXPRESSIONS (META_CXX_VER >= META_CXX_STD_17)
#endif
#endif
#if META_CXX_FOLD_EXPRESSIONS
#if !META_CXX_VARIABLE_TEMPLATES
#error Fold expressions, but no variable templates?
#endif
#endif
#if (defined(__cpp_concepts) && __cpp_concepts > 0) || defined(META_DOXYGEN_INVOKED)
#if !META_CXX_VARIABLE_TEMPLATES
#error Concepts, but no variable templates?
#endif
#if __cpp_concepts <= 201507L && !defined(META_DOXYGEN_INVOKED)
#define META_CONCEPT concept bool
// TS concepts subsumption barrier for atomic expressions
#define META_CONCEPT_BARRIER(...) ::meta::detail::barrier<__VA_ARGS__>
#define META_TYPE_CONSTRAINT(...) typename
#else
#define META_CONCEPT concept
#define META_CONCEPT_BARRIER(...) __VA_ARGS__
#define META_TYPE_CONSTRAINT(...) __VA_ARGS__
#endif
#else
#define META_TYPE_CONSTRAINT(...) typename
#endif
#if (defined(__cpp_lib_type_trait_variable_templates) && \
__cpp_lib_type_trait_variable_templates > 0)
#define META_CXX_TRAIT_VARIABLE_TEMPLATES 1
#else
#define META_CXX_TRAIT_VARIABLE_TEMPLATES 0
#endif
#if defined(__clang__)
#define META_IS_SAME(...) __is_same(__VA_ARGS__)
#elif defined(__GNUC__) && __GNUC__ >= 6
#define META_IS_SAME(...) __is_same_as(__VA_ARGS__)
#elif META_CXX_TRAIT_VARIABLE_TEMPLATES
#define META_IS_SAME(...) std::is_same_v<__VA_ARGS__>
#else
#define META_IS_SAME(...) std::is_same<__VA_ARGS__>::value
#endif
#if defined(__GNUC__) || defined(_MSC_VER)
#define META_IS_BASE_OF(...) __is_base_of(__VA_ARGS__)
#elif META_CXX_TRAIT_VARIABLE_TEMPLATES
#define META_IS_BASE_OF(...) std::is_base_of_v<__VA_ARGS__>
#else
#define META_IS_BASE_OF(...) std::is_base_of<__VA_ARGS__>::value
#endif
#if defined(__clang__) || defined(_MSC_VER) || \
(defined(__GNUC__) && __GNUC__ >= 8)
#define META_IS_CONSTRUCTIBLE(...) __is_constructible(__VA_ARGS__)
#elif META_CXX_TRAIT_VARIABLE_TEMPLATES
#define META_IS_CONSTRUCTIBLE(...) std::is_constructible_v<__VA_ARGS__>
#else
#define META_IS_CONSTRUCTIBLE(...) std::is_constructible<__VA_ARGS__>::value
#endif
/// \cond
// Non-portable forward declarations of standard containers
#ifdef _LIBCPP_VERSION
#define META_BEGIN_NAMESPACE_STD _LIBCPP_BEGIN_NAMESPACE_STD
#define META_END_NAMESPACE_STD _LIBCPP_END_NAMESPACE_STD
#elif defined(_MSVC_STL_VERSION)
#define META_BEGIN_NAMESPACE_STD _STD_BEGIN
#define META_END_NAMESPACE_STD _STD_END
#else
#define META_BEGIN_NAMESPACE_STD namespace std {
#define META_END_NAMESPACE_STD }
#endif
#if defined(__GLIBCXX__)
#define META_BEGIN_NAMESPACE_VERSION _GLIBCXX_BEGIN_NAMESPACE_VERSION
#define META_END_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION
#define META_BEGIN_NAMESPACE_CONTAINER _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
#define META_END_NAMESPACE_CONTAINER _GLIBCXX_END_NAMESPACE_CONTAINER
#else
#define META_BEGIN_NAMESPACE_VERSION
#define META_END_NAMESPACE_VERSION
#define META_BEGIN_NAMESPACE_CONTAINER
#define META_END_NAMESPACE_CONTAINER
#endif
#if defined(_LIBCPP_VERSION) && _LIBCPP_VERSION >= 4000
#define META_TEMPLATE_VIS _LIBCPP_TEMPLATE_VIS
#elif defined(_LIBCPP_VERSION)
#define META_TEMPLATE_VIS _LIBCPP_TYPE_VIS_ONLY
#else
#define META_TEMPLATE_VIS
#endif
/// \endcond
namespace meta
{
#if META_CXX_INTEGER_SEQUENCE
using std::integer_sequence;
#else
template <typename T, T...>
struct integer_sequence;
#endif
template <typename... Ts>
struct list;
template <typename T>
struct id;
template <template <typename...> class>
struct quote;
template <typename T, template <T...> class F>
struct quote_i;
template <template <typename...> class C, typename... Ts>
struct defer;
template <typename T, template <T...> class C, T... Is>
struct defer_i;
#if META_CXX_VARIABLE_TEMPLATES || defined(META_DOXYGEN_INVOKED)
/// is_v
/// Test whether a type \p T is an instantiation of class
/// template \p C.
/// \ingroup trait
template <typename, template <typename...> class>
META_INLINE_VAR constexpr bool is_v = false;
template <typename... Ts, template <typename...> class C>
META_INLINE_VAR constexpr bool is_v<C<Ts...>, C> = true;
#endif
#ifdef META_CONCEPT
namespace detail
{
template <bool B>
META_INLINE_VAR constexpr bool barrier = B;
template <class T, T> struct require_constant; // not defined
}
template <typename...>
META_CONCEPT is_true = META_CONCEPT_BARRIER(true);
template <typename T, typename U>
META_CONCEPT same_as =
META_CONCEPT_BARRIER(META_IS_SAME(T, U));
template <template <typename...> class C, typename... Ts>
META_CONCEPT valid = requires
{
typename C<Ts...>;
};
template <typename T, template <T...> class C, T... Is>
META_CONCEPT valid_i = requires
{
typename C<Is...>;
};
template <typename T>
META_CONCEPT trait = requires
{
typename T::type;
};
template <typename T>
META_CONCEPT invocable = requires
{
typename quote<T::template invoke>;
};
template <typename T>
META_CONCEPT list_like = is_v<T, list>;
// clang-format off
template <typename T>
META_CONCEPT integral = requires
{
typename T::type;
typename T::value_type;
typename T::type::value_type;
}
&& same_as<typename T::value_type, typename T::type::value_type>
#if META_CXX_TRAIT_VARIABLE_TEMPLATES
&& std::is_integral_v<typename T::value_type>
#else
&& std::is_integral<typename T::value_type>::value
#endif
&& requires
{
// { T::value } -> same_as<const typename T::value_type&>;
T::value;
requires same_as<decltype(T::value), const typename T::value_type>;
typename detail::require_constant<decltype(T::value), T::value>;
// { T::type::value } -> same_as<const typename T::value_type&>;
T::type::value;
requires same_as<decltype(T::type::value), const typename T::value_type>;
typename detail::require_constant<decltype(T::type::value), T::type::value>;
requires T::value == T::type::value;
// { T{}() } -> same_as<typename T::value_type>;
T{}();
requires same_as<decltype(T{}()), typename T::value_type>;
typename detail::require_constant<decltype(T{}()), T{}()>;
requires T{}() == T::value;
// { T{} } -> typename T::value_type;
};
// clang-format on
#endif // META_CONCEPT
namespace extension
{
template <META_TYPE_CONSTRAINT(invocable) F, typename L>
struct apply;
}
} // namespace meta
#ifdef __clang__
#pragma GCC diagnostic pop
#endif
#endif
|
0 | repos/range-v3/include | repos/range-v3/include/meta/meta.hpp | /// \file meta.hpp Tiny meta-programming library.
//
// Meta library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/meta
//
#ifndef META_HPP
#define META_HPP
#include <cstddef>
#include <initializer_list>
#include <meta/meta_fwd.hpp>
#include <type_traits>
#include <utility>
#ifdef __clang__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunknown-pragmas"
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Wdocumentation-deprecated-sync"
#pragma GCC diagnostic ignored "-Wmissing-variable-declarations"
#pragma GCC diagnostic ignored "-Wunknown-warning-option"
#pragma GCC diagnostic ignored "-Wreserved-identifier" // _z at namespace scope is not reserved
#endif
/// \defgroup meta Meta
///
/// A tiny metaprogramming library
/// \defgroup trait Trait
/// Trait invocation/composition.
/// \ingroup meta
/// \defgroup invocation Invocation
/// Trait invocation
/// \ingroup trait
/// \defgroup composition Composition
/// Trait composition
/// \ingroup trait
/// \defgroup logical Logical
/// Logical operations
/// \ingroup meta
/// \defgroup algorithm Algorithms
/// Algorithms.
/// \ingroup meta
/// \defgroup query Query/Search
/// Query and search algorithms
/// \ingroup algorithm
/// \defgroup transformation Transformation
/// Transformation algorithms
/// \ingroup algorithm
/// \defgroup runtime Runtime
/// Runtime algorithms
/// \ingroup algorithm
/// \defgroup datatype Datatype
/// Datatypes.
/// \ingroup meta
/// \defgroup list list_like
/// \ingroup datatype
/// \defgroup integral Integer sequence
/// Equivalent to C++14's `std::integer_sequence`
/// \ingroup datatype
/// \defgroup extension Extension
/// Extend meta with your own datatypes.
/// \ingroup datatype
/// \defgroup math Math
/// Integral constant arithmetic.
/// \ingroup meta
/// \defgroup lazy_trait lazy
/// \ingroup trait
/// \defgroup lazy_invocation lazy
/// \ingroup invocation
/// \defgroup lazy_composition lazy
/// \ingroup composition
/// \defgroup lazy_logical lazy
/// \ingroup logical
/// \defgroup lazy_query lazy
/// \ingroup query
/// \defgroup lazy_transformation lazy
/// \ingroup transformation
/// \defgroup lazy_list lazy
/// \ingroup list
/// \defgroup lazy_datatype lazy
/// \ingroup datatype
/// \defgroup lazy_math lazy
/// \ingroup math
/// Tiny metaprogramming library
namespace meta
{
namespace detail
{
/// Returns a \p T nullptr
template <typename T>
constexpr T *_nullptr_v()
{
return nullptr;
}
#if META_CXX_VARIABLE_TEMPLATES
template <typename T>
META_INLINE_VAR constexpr T *nullptr_v = nullptr;
#endif
} // namespace detail
/// An empty type.
/// \ingroup datatype
struct nil_
{
};
/// Type alias for \p T::type.
/// \ingroup invocation
template <META_TYPE_CONSTRAINT(trait) T>
using _t = typename T::type;
#if META_CXX_VARIABLE_TEMPLATES || defined(META_DOXYGEN_INVOKED)
/// Variable alias for \c T::type::value
/// \note Requires C++14 or greater.
/// \ingroup invocation
template <META_TYPE_CONSTRAINT(integral) T>
constexpr typename T::type::value_type _v = T::type::value;
#endif
/// Lazy versions of meta actions
namespace lazy
{
/// \sa `meta::_t`
/// \ingroup lazy_invocation
template <typename T>
using _t = defer<_t, T>;
} // namespace lazy
/// An integral constant wrapper for \c std::size_t.
/// \ingroup integral
template <std::size_t N>
using size_t = std::integral_constant<std::size_t, N>;
/// An integral constant wrapper for \c bool.
/// \ingroup integral
template <bool B>
using bool_ = std::integral_constant<bool, B>;
/// An integral constant wrapper for \c int.
/// \ingroup integral
template <int Int>
using int_ = std::integral_constant<int, Int>;
/// An integral constant wrapper for \c char.
/// \ingroup integral
template <char Ch>
using char_ = std::integral_constant<char, Ch>;
///////////////////////////////////////////////////////////////////////////////////////////
// Math operations
/// An integral constant wrapper around the result of incrementing the wrapped integer \c
/// T::type::value.
template <META_TYPE_CONSTRAINT(integral) T>
using inc = std::integral_constant<decltype(T::type::value + 1), T::type::value + 1>;
/// An integral constant wrapper around the result of decrementing the wrapped integer \c
/// T::type::value.
template <META_TYPE_CONSTRAINT(integral) T>
using dec = std::integral_constant<decltype(T::type::value - 1), T::type::value - 1>;
/// An integral constant wrapper around the result of adding the two wrapped integers
/// \c T::type::value and \c U::type::value.
/// \ingroup math
template <META_TYPE_CONSTRAINT(integral) T, META_TYPE_CONSTRAINT(integral) U>
using plus = std::integral_constant<decltype(T::type::value + U::type::value),
T::type::value + U::type::value>;
/// An integral constant wrapper around the result of subtracting the two wrapped integers
/// \c T::type::value and \c U::type::value.
/// \ingroup math
template <META_TYPE_CONSTRAINT(integral) T, META_TYPE_CONSTRAINT(integral) U>
using minus = std::integral_constant<decltype(T::type::value - U::type::value),
T::type::value - U::type::value>;
/// An integral constant wrapper around the result of multiplying the two wrapped integers
/// \c T::type::value and \c U::type::value.
/// \ingroup math
template <META_TYPE_CONSTRAINT(integral) T, META_TYPE_CONSTRAINT(integral) U>
using multiplies = std::integral_constant<decltype(T::type::value * U::type::value),
T::type::value * U::type::value>;
/// An integral constant wrapper around the result of dividing the two wrapped integers \c
/// T::type::value and \c U::type::value.
/// \ingroup math
template <META_TYPE_CONSTRAINT(integral) T, META_TYPE_CONSTRAINT(integral) U>
using divides = std::integral_constant<decltype(T::type::value / U::type::value),
T::type::value / U::type::value>;
/// An integral constant wrapper around the result of negating the wrapped integer
/// \c T::type::value.
/// \ingroup math
template <META_TYPE_CONSTRAINT(integral) T>
using negate = std::integral_constant<decltype(-T::type::value), -T::type::value>;
/// An integral constant wrapper around the remainder of dividing the two wrapped integers
/// \c T::type::value and \c U::type::value.
/// \ingroup math
template <META_TYPE_CONSTRAINT(integral) T, META_TYPE_CONSTRAINT(integral) U>
using modulus = std::integral_constant<decltype(T::type::value % U::type::value),
T::type::value % U::type::value>;
/// A Boolean integral constant wrapper around the result of comparing \c T::type::value and
/// \c U::type::value for equality.
/// \ingroup math
template <META_TYPE_CONSTRAINT(integral) T, META_TYPE_CONSTRAINT(integral) U>
using equal_to = bool_<T::type::value == U::type::value>;
/// A Boolean integral constant wrapper around the result of comparing \c T::type::value and
/// \c U::type::value for inequality.
/// \ingroup math
template <META_TYPE_CONSTRAINT(integral) T, META_TYPE_CONSTRAINT(integral) U>
using not_equal_to = bool_<T::type::value != U::type::value>;
/// A Boolean integral constant wrapper around \c true if \c T::type::value is greater than
/// \c U::type::value; \c false, otherwise.
/// \ingroup math
template <META_TYPE_CONSTRAINT(integral) T, META_TYPE_CONSTRAINT(integral) U>
using greater = bool_<(T::type::value > U::type::value)>;
/// A Boolean integral constant wrapper around \c true if \c T::type::value is less than \c
/// U::type::value; \c false, otherwise.
/// \ingroup math
template <META_TYPE_CONSTRAINT(integral) T, META_TYPE_CONSTRAINT(integral) U>
using less = bool_<(T::type::value < U::type::value)>;
/// A Boolean integral constant wrapper around \c true if \c T::type::value is greater than
/// or equal to \c U::type::value; \c false, otherwise.
/// \ingroup math
template <META_TYPE_CONSTRAINT(integral) T, META_TYPE_CONSTRAINT(integral) U>
using greater_equal = bool_<(T::type::value >= U::type::value)>;
/// A Boolean integral constant wrapper around \c true if \c T::type::value is less than or
/// equal to \c U::type::value; \c false, otherwise.
/// \ingroup math
template <META_TYPE_CONSTRAINT(integral) T, META_TYPE_CONSTRAINT(integral) U>
using less_equal = bool_<(T::type::value <= U::type::value)>;
/// An integral constant wrapper around the result of bitwise-and'ing the two wrapped
/// integers \c T::type::value and \c U::type::value.
/// \ingroup math
template <META_TYPE_CONSTRAINT(integral) T, META_TYPE_CONSTRAINT(integral) U>
using bit_and = std::integral_constant<decltype(T::type::value & U::type::value),
T::type::value & U::type::value>;
/// An integral constant wrapper around the result of bitwise-or'ing the two wrapped
/// integers \c T::type::value and \c U::type::value.
/// \ingroup math
template <META_TYPE_CONSTRAINT(integral) T, META_TYPE_CONSTRAINT(integral) U>
using bit_or = std::integral_constant<decltype(T::type::value | U::type::value),
T::type::value | U::type::value>;
/// An integral constant wrapper around the result of bitwise-exclusive-or'ing the two
/// wrapped integers \c T::type::value and \c U::type::value.
/// \ingroup math
template <META_TYPE_CONSTRAINT(integral) T, META_TYPE_CONSTRAINT(integral) U>
using bit_xor = std::integral_constant<decltype(T::type::value ^ U::type::value),
T::type::value ^ U::type::value>;
/// An integral constant wrapper around the result of bitwise-complementing the wrapped
/// integer \c T::type::value.
/// \ingroup math
template <META_TYPE_CONSTRAINT(integral) T>
using bit_not = std::integral_constant<decltype(~T::type::value), ~T::type::value>;
namespace lazy
{
/// \sa 'meta::int'
/// \ingroup lazy_math
template <typename T>
using inc = defer<inc, T>;
/// \sa 'meta::dec'
/// \ingroup lazy_math
template <typename T>
using dec = defer<dec, T>;
/// \sa 'meta::plus'
/// \ingroup lazy_math
template <typename T, typename U>
using plus = defer<plus, T, U>;
/// \sa 'meta::minus'
/// \ingroup lazy_math
template <typename T, typename U>
using minus = defer<minus, T, U>;
/// \sa 'meta::multiplies'
/// \ingroup lazy_math
template <typename T, typename U>
using multiplies = defer<multiplies, T, U>;
/// \sa 'meta::divides'
/// \ingroup lazy_math
template <typename T, typename U>
using divides = defer<divides, T, U>;
/// \sa 'meta::negate'
/// \ingroup lazy_math
template <typename T>
using negate = defer<negate, T>;
/// \sa 'meta::modulus'
/// \ingroup lazy_math
template <typename T, typename U>
using modulus = defer<modulus, T, U>;
/// \sa 'meta::equal_to'
/// \ingroup lazy_math
template <typename T, typename U>
using equal_to = defer<equal_to, T, U>;
/// \sa 'meta::not_equal_t'
/// \ingroup lazy_math
template <typename T, typename U>
using not_equal_to = defer<not_equal_to, T, U>;
/// \sa 'meta::greater'
/// \ingroup lazy_math
template <typename T, typename U>
using greater = defer<greater, T, U>;
/// \sa 'meta::less'
/// \ingroup lazy_math
template <typename T, typename U>
using less = defer<less, T, U>;
/// \sa 'meta::greater_equal'
/// \ingroup lazy_math
template <typename T, typename U>
using greater_equal = defer<greater_equal, T, U>;
/// \sa 'meta::less_equal'
/// \ingroup lazy_math
template <typename T, typename U>
using less_equal = defer<less_equal, T, U>;
/// \sa 'meta::bit_and'
/// \ingroup lazy_math
template <typename T, typename U>
using bit_and = defer<bit_and, T, U>;
/// \sa 'meta::bit_or'
/// \ingroup lazy_math
template <typename T, typename U>
using bit_or = defer<bit_or, T, U>;
/// \sa 'meta::bit_xor'
/// \ingroup lazy_math
template <typename T, typename U>
using bit_xor = defer<bit_xor, T, U>;
/// \sa 'meta::bit_not'
/// \ingroup lazy_math
template <typename T>
using bit_not = defer<bit_not, T>;
} // namespace lazy
/// \cond
namespace detail
{
enum class indices_strategy_
{
done,
repeat,
recurse
};
constexpr indices_strategy_ strategy_(std::size_t cur, std::size_t end)
{
return cur >= end ? indices_strategy_::done
: cur * 2 <= end ? indices_strategy_::repeat
: indices_strategy_::recurse;
}
template <typename T>
constexpr std::size_t range_distance_(T begin, T end)
{
return begin <= end ? static_cast<std::size_t>(end - begin)
: throw "The start of the integer_sequence must not be "
"greater than the end";
}
template <std::size_t End, typename State, indices_strategy_ Status_>
struct make_indices_
{
using type = State;
};
template <typename T, T, typename>
struct coerce_indices_
{
};
} // namespace detail
/// \endcond
///////////////////////////////////////////////////////////////////////////////////////////
// integer_sequence
#if !META_CXX_INTEGER_SEQUENCE
/// A container for a sequence of compile-time integer constants.
/// \ingroup integral
template <typename T, T... Is>
struct integer_sequence
{
using value_type = T;
/// \return `sizeof...(Is)`
static constexpr std::size_t size() noexcept { return sizeof...(Is); }
};
#endif
///////////////////////////////////////////////////////////////////////////////////////////
// index_sequence
/// A container for a sequence of compile-time integer constants of type
/// \c std::size_t
/// \ingroup integral
template <std::size_t... Is>
using index_sequence = integer_sequence<std::size_t, Is...>;
#if META_HAS_MAKE_INTEGER_SEQ && !defined(META_DOXYGEN_INVOKED)
// Implement make_integer_sequence and make_index_sequence with the
// __make_integer_seq builtin on compilers that provide it. (Redirect
// through decltype to workaround suspected clang bug.)
/// \cond
namespace detail
{
template <typename T, T N>
__make_integer_seq<integer_sequence, T, N> make_integer_sequence_();
}
/// \endcond
template <typename T, T N>
using make_integer_sequence = decltype(detail::make_integer_sequence_<T, N>());
template <std::size_t N>
using make_index_sequence = make_integer_sequence<std::size_t, N>;
#else
/// Generate \c index_sequence containing integer constants [0,1,2,...,N-1].
/// \par Complexity
/// `O(log(N))`.
/// \ingroup integral
template <std::size_t N>
using make_index_sequence =
_t<detail::make_indices_<N, index_sequence<0>, detail::strategy_(1, N)>>;
/// Generate \c integer_sequence containing integer constants [0,1,2,...,N-1].
/// \par Complexity
/// `O(log(N))`.
/// \ingroup integral
template <typename T, T N>
using make_integer_sequence =
_t<detail::coerce_indices_<T, 0, make_index_sequence<static_cast<std::size_t>(N)>>>;
#endif
///////////////////////////////////////////////////////////////////////////////////////////
// integer_range
/// Makes the integer sequence `[From, To)`.
/// \par Complexity
/// `O(log(To - From))`.
/// \ingroup integral
template <typename T, T From, T To>
using integer_range =
_t<detail::coerce_indices_<T, From,
make_index_sequence<detail::range_distance_(From, To)>>>;
/// \cond
namespace detail
{
template <typename, typename>
struct concat_indices_
{
};
template <std::size_t... Is, std::size_t... Js>
struct concat_indices_<index_sequence<Is...>, index_sequence<Js...>>
{
using type = index_sequence<Is..., (Js + sizeof...(Is))...>;
};
template <>
struct make_indices_<0u, index_sequence<0>, indices_strategy_::done>
{
using type = index_sequence<>;
};
template <std::size_t End, std::size_t... Values>
struct make_indices_<End, index_sequence<Values...>, indices_strategy_::repeat>
: make_indices_<End, index_sequence<Values..., (Values + sizeof...(Values))...>,
detail::strategy_(sizeof...(Values) * 2, End)>
{
};
template <std::size_t End, std::size_t... Values>
struct make_indices_<End, index_sequence<Values...>, indices_strategy_::recurse>
: concat_indices_<index_sequence<Values...>,
make_index_sequence<End - sizeof...(Values)>>
{
};
template <typename T, T Offset, std::size_t... Values>
struct coerce_indices_<T, Offset, index_sequence<Values...>>
{
using type =
integer_sequence<T, static_cast<T>(static_cast<T>(Values) + Offset)...>;
};
} // namespace detail
/// \endcond
/// Evaluate the invocable \p Fn with the arguments \p Args.
/// \ingroup invocation
template <META_TYPE_CONSTRAINT(invocable) Fn, typename... Args>
using invoke = typename Fn::template invoke<Args...>;
/// Lazy versions of meta actions
namespace lazy
{
/// \sa `meta::invoke`
/// \ingroup lazy_invocation
template <typename Fn, typename... Args>
using invoke = defer<invoke, Fn, Args...>;
} // namespace lazy
/// A trait that always returns its argument \p T. It is also an invocable
/// that always returns \p T.
/// \ingroup trait
/// \ingroup invocation
template <typename T>
struct id
{
#if defined(META_WORKAROUND_CWG_1558) && !defined(META_DOXYGEN_INVOKED)
// Redirect through decltype for compilers that have not
// yet implemented CWG 1558:
static id impl(void *);
template <typename... Ts>
using invoke = _t<decltype(id::impl(static_cast<list<Ts...> *>(nullptr)))>;
#else
template <typename...>
using invoke = T;
#endif
using type = T;
};
/// An alias for type \p T. Useful in non-deduced contexts.
/// \ingroup trait
template <typename T>
using id_t = _t<id<T>>;
namespace lazy
{
/// \sa `meta::id`
/// \ingroup lazy_trait
/// \ingroup lazy_invocation
template <typename T>
using id = defer<id, T>;
} // namespace lazy
/// An alias for `void`.
/// \ingroup trait
#if defined(META_WORKAROUND_CWG_1558) && !defined(META_DOXYGEN_INVOKED)
// Redirect through decltype for compilers that have not
// yet implemented CWG 1558:
template <typename... Ts>
using void_ = invoke<id<void>, Ts...>;
#else
template <typename...>
using void_ = void;
#endif
#if META_CXX_VARIABLE_TEMPLATES
#ifdef META_CONCEPT
/// `true` if `T::type` exists and names a type; `false` otherwise.
/// \ingroup trait
template <typename T>
META_INLINE_VAR constexpr bool is_trait_v = trait<T>;
/// `true` if `T::invoke` exists and names a class template; `false` otherwise.
/// \ingroup trait
template <typename T>
META_INLINE_VAR constexpr bool is_callable_v = invocable<T>;
#else // ^^^ Concepts / No concepts vvv
/// \cond
namespace detail
{
template <typename, typename = void>
META_INLINE_VAR constexpr bool is_trait_ = false;
template <typename T>
META_INLINE_VAR constexpr bool is_trait_<T, void_<typename T::type>> = true;
template <typename, typename = void>
META_INLINE_VAR constexpr bool is_callable_ = false;
template <typename T>
META_INLINE_VAR constexpr bool is_callable_<T, void_<quote<T::template invoke>>> = true;
} // namespace detail
/// \endcond
/// `true` if `T::type` exists and names a type; `false` otherwise.
/// \ingroup trait
template <typename T>
META_INLINE_VAR constexpr bool is_trait_v = detail::is_trait_<T>;
/// `true` if `T::invoke` exists and names a class template; `false` otherwise.
/// \ingroup trait
template <typename T>
META_INLINE_VAR constexpr bool is_callable_v = detail::is_callable_<T>;
#endif // Concepts vs. variable templates
/// An alias for `std::true_type` if `T::type` exists and names a type; otherwise, it's an
/// alias for `std::false_type`.
/// \ingroup trait
template <typename T>
using is_trait = bool_<is_trait_v<T>>;
/// An alias for `std::true_type` if `T::invoke` exists and names a class template;
/// otherwise, it's an alias for `std::false_type`.
/// \ingroup trait
template <typename T>
using is_callable = bool_<is_callable_v<T>>;
#else // ^^^ META_CXX_VARIABLE_TEMPLATES / !META_CXX_VARIABLE_TEMPLATES vvv
/// \cond
namespace detail
{
template <typename, typename = void>
struct is_trait_
{
using type = std::false_type;
};
template <typename T>
struct is_trait_<T, void_<typename T::type>>
{
using type = std::true_type;
};
template <typename, typename = void>
struct is_callable_
{
using type = std::false_type;
};
template <typename T>
struct is_callable_<T, void_<quote<T::template invoke>>>
{
using type = std::true_type;
};
} // namespace detail
/// \endcond
template <typename T>
using is_trait = _t<detail::is_trait_<T>>;
/// An alias for `std::true_type` if `T::invoke` exists and names a class
/// template or alias template; otherwise, it's an alias for
/// `std::false_type`.
/// \ingroup trait
template <typename T>
using is_callable = _t<detail::is_callable_<T>>;
#endif
/// \cond
namespace detail
{
#ifdef META_CONCEPT
template <template <typename...> class, typename...>
struct defer_
{
};
template <template <typename...> class C, typename... Ts>
requires valid<C, Ts...> struct defer_<C, Ts...>
{
using type = C<Ts...>;
};
template <typename T, template <T...> class, T...>
struct defer_i_
{
};
template <typename T, template <T...> class C, T... Is>
requires valid_i<T, C, Is...> struct defer_i_<T, C, Is...>
{
using type = C<Is...>;
};
#elif defined(META_WORKAROUND_MSVC_703656) // ^^^ Concepts / MSVC workaround vvv
template <typename, template <typename...> class, typename...>
struct _defer_
{
};
template <template <typename...> class C, typename... Ts>
struct _defer_<void_<C<Ts...>>, C, Ts...>
{
using type = C<Ts...>;
};
template <template <typename...> class C, typename... Ts>
using defer_ = _defer_<void, C, Ts...>;
template <typename, typename T, template <T...> class, T...>
struct _defer_i_
{
};
template <typename T, template <T...> class C, T... Is>
struct _defer_i_<void_<C<Is...>>, T, C, Is...>
{
using type = C<Is...>;
};
template <typename T, template <T...> class C, T... Is>
using defer_i_ = _defer_i_<void, T, C, Is...>;
#else // ^^^ workaround ^^^ / vvv no workaround vvv
template <template <typename...> class C, typename... Ts,
template <typename...> class D = C>
id<D<Ts...>> try_defer_(int);
template <template <typename...> class C, typename... Ts>
nil_ try_defer_(long);
template <template <typename...> class C, typename... Ts>
using defer_ = decltype(detail::try_defer_<C, Ts...>(0));
template <typename T, template <T...> class C, T... Is, template <T...> class D = C>
id<D<Is...>> try_defer_i_(int);
template <typename T, template <T...> class C, T... Is>
nil_ try_defer_i_(long);
template <typename T, template <T...> class C, T... Is>
using defer_i_ = decltype(detail::try_defer_i_<T, C, Is...>(0));
#endif // Concepts vs. MSVC vs. Other
template <typename T>
using _t_t = _t<_t<T>>;
} // namespace detail
/// \endcond
///////////////////////////////////////////////////////////////////////////////////////////
// defer
/// A wrapper that defers the instantiation of a template \p C with type parameters \p Ts in
/// a \c lambda or \c let expression.
///
/// In the code below, the lambda would ideally be written as
/// `lambda<_a,_b,push_back<_a,_b>>`, however this fails since `push_back` expects its first
/// argument to be a list, not a placeholder. Instead, we express it using \c defer as
/// follows:
///
/// \code
/// template <typename L>
/// using reverse = reverse_fold<L, list<>, lambda<_a, _b, defer<push_back, _a, _b>>>;
/// \endcode
///
/// \ingroup invocation
template <template <typename...> class C, typename... Ts>
struct defer : detail::defer_<C, Ts...>
{
};
///////////////////////////////////////////////////////////////////////////////////////////
// defer_i
/// A wrapper that defers the instantiation of a template \p C with integral constant
/// parameters \p Is in a \c lambda or \c let expression.
/// \sa `defer`
/// \ingroup invocation
template <typename T, template <T...> class C, T... Is>
struct defer_i : detail::defer_i_<T, C, Is...>
{
};
///////////////////////////////////////////////////////////////////////////////////////////
// defer_trait
/// A wrapper that defers the instantiation of a trait \p C with type parameters \p Ts in a
/// \c lambda or \c let expression.
/// \sa `defer`
/// \ingroup invocation
template <template <typename...> class C, typename... Ts>
using defer_trait = defer<detail::_t_t, detail::defer_<C, Ts...>>;
///////////////////////////////////////////////////////////////////////////////////////////
// defer_trait_i
/// A wrapper that defers the instantiation of a trait \p C with integral constant
/// parameters \p Is in a \c lambda or \c let expression.
/// \sa `defer_i`
/// \ingroup invocation
template <typename T, template <T...> class C, T... Is>
using defer_trait_i = defer<detail::_t_t, detail::defer_i_<T, C, Is...>>;
/// An alias that computes the size of the type \p T.
/// \par Complexity
/// `O(1)`.
/// \ingroup trait
template <typename T>
using sizeof_ = meta::size_t<sizeof(T)>;
/// An alias that computes the alignment required for any instance of the type \p T.
/// \par Complexity
/// `O(1)`.
/// \ingroup trait
template <typename T>
using alignof_ = meta::size_t<alignof(T)>;
namespace lazy
{
/// \sa `meta::sizeof_`
/// \ingroup lazy_trait
template <typename T>
using sizeof_ = defer<sizeof_, T>;
/// \sa `meta::alignof_`
/// \ingroup lazy_trait
template <typename T>
using alignof_ = defer<alignof_, T>;
} // namespace lazy
#if META_CXX_VARIABLE_TEMPLATES
/// is
/// Test whether a type \p T is an instantiation of class
/// template \p C.
/// \ingroup trait
template <typename T, template <typename...> class C>
using is = bool_<is_v<T, C>>;
#else
/// is
/// \cond
namespace detail
{
template <typename, template <typename...> class>
struct is_ : std::false_type
{
};
template <typename... Ts, template <typename...> class C>
struct is_<C<Ts...>, C> : std::true_type
{
};
} // namespace detail
/// \endcond
/// Test whether a type \c T is an instantiation of class
/// template \c C.
/// \ingroup trait
template <typename T, template <typename...> class C>
using is = _t<detail::is_<T, C>>;
#endif
/// Compose the Invocables \p Fns in the parameter pack \p Ts.
/// \ingroup composition
template <META_TYPE_CONSTRAINT(invocable)... Fns>
struct compose_
{
};
template <META_TYPE_CONSTRAINT(invocable) Fn0>
struct compose_<Fn0>
{
template <typename... Ts>
using invoke = invoke<Fn0, Ts...>;
};
template <META_TYPE_CONSTRAINT(invocable) Fn0, META_TYPE_CONSTRAINT(invocable)... Fns>
struct compose_<Fn0, Fns...>
{
template <typename... Ts>
using invoke = invoke<Fn0, invoke<compose_<Fns...>, Ts...>>;
};
template <typename... Fns>
using compose = compose_<Fns...>;
namespace lazy
{
/// \sa 'meta::compose'
/// \ingroup lazy_composition
template <typename... Fns>
using compose = defer<compose, Fns...>;
} // namespace lazy
/// Turn a template \p C into an invocable.
/// \ingroup composition
template <template <typename...> class C>
struct quote
{
// Indirection through defer here needed to avoid Core issue 1430
// https://wg21.link/cwg1430
template <typename... Ts>
using invoke = _t<defer<C, Ts...>>;
};
/// Turn a template \p C taking literals of type \p T into a
/// invocable.
/// \ingroup composition
template <typename T, template <T...> class C>
struct quote_i
{
// Indirection through defer_i here needed to avoid Core issue 1430
// https://wg21.link/cwg1430
template <META_TYPE_CONSTRAINT(integral)... Ts>
using invoke = _t<defer_i<T, C, Ts::type::value...>>;
};
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ == 4 && __GNUC_MINOR__ <= 8 && \
!defined(META_DOXYGEN_INVOKED)
template <template <typename...> class C>
struct quote_trait
{
template <typename... Ts>
using invoke = _t<invoke<quote<C>, Ts...>>;
};
template <typename T, template <T...> class C>
struct quote_trait_i
{
template <typename... Ts>
using invoke = _t<invoke<quote_i<T, C>, Ts...>>;
};
#else
// clang-format off
/// Turn a trait template \p C into an invocable.
/// \code
/// static_assert(std::is_same_v<invoke<quote_trait<std::add_const>, int>, int const>, "");
/// \endcode
/// \ingroup composition
template <template <typename...> class C>
using quote_trait = compose<quote<_t>, quote<C>>;
/// Turn a trait template \p C taking literals of type \p T into an invocable.
/// \ingroup composition
template <typename T, template <T...> class C>
using quote_trait_i = compose<quote<_t>, quote_i<T, C>>;
// clang-format on
#endif
/// An invocable that partially applies the invocable
/// \p Fn by binding the arguments \p Ts to the \e front of \p Fn.
/// \ingroup composition
template <META_TYPE_CONSTRAINT(invocable) Fn, typename... Ts>
struct bind_front
{
template <typename... Us>
using invoke = invoke<Fn, Ts..., Us...>;
};
/// An invocable that partially applies the invocable \p Fn by binding the
/// arguments \p Us to the \e back of \p Fn.
/// \ingroup composition
template <META_TYPE_CONSTRAINT(invocable) Fn, typename... Us>
struct bind_back
{
template <typename... Ts>
using invoke = invoke<Fn, Ts..., Us...>;
};
namespace lazy
{
/// \sa 'meta::bind_front'
/// \ingroup lazy_composition
template <typename Fn, typename... Ts>
using bind_front = defer<bind_front, Fn, Ts...>;
/// \sa 'meta::bind_back'
/// \ingroup lazy_composition
template <typename Fn, typename... Ts>
using bind_back = defer<bind_back, Fn, Ts...>;
} // namespace lazy
/// Extend meta with your own datatypes.
namespace extension
{
/// A trait that unpacks the types in the type list \p L into the invocable
/// \p Fn.
/// \ingroup extension
template <META_TYPE_CONSTRAINT(invocable) Fn, typename L>
struct apply
{
};
template <META_TYPE_CONSTRAINT(invocable) Fn, typename Ret, typename... Args>
struct apply<Fn, Ret(Args...)> : lazy::invoke<Fn, Ret, Args...>
{
};
template <META_TYPE_CONSTRAINT(invocable) Fn, template <typename...> class T,
typename... Ts>
struct apply<Fn, T<Ts...>> : lazy::invoke<Fn, Ts...>
{
};
template <META_TYPE_CONSTRAINT(invocable) Fn, typename T, T... Is>
struct apply<Fn, integer_sequence<T, Is...>>
: lazy::invoke<Fn, std::integral_constant<T, Is>...>
{
};
} // namespace extension
/// Applies the invocable \p Fn using the types in the type list \p L as
/// arguments.
/// \ingroup invocation
template <META_TYPE_CONSTRAINT(invocable) Fn, typename L>
using apply = _t<extension::apply<Fn, L>>;
namespace lazy
{
template <typename Fn, typename L>
using apply = defer<apply, Fn, L>;
}
/// An invocable that takes a bunch of arguments, bundles them into a type
/// list, and then calls the invocable \p Fn with the type list \p Q.
/// \ingroup composition
template <META_TYPE_CONSTRAINT(invocable) Fn,
META_TYPE_CONSTRAINT(invocable) Q = quote<list>>
using curry = compose<Fn, Q>;
/// An invocable that takes a type list, unpacks the types, and then
/// calls the invocable \p Fn with the types.
/// \ingroup composition
template <META_TYPE_CONSTRAINT(invocable) Fn>
using uncurry = bind_front<quote<apply>, Fn>;
namespace lazy
{
/// \sa 'meta::curry'
/// \ingroup lazy_composition
template <typename Fn, typename Q = quote<list>>
using curry = defer<curry, Fn, Q>;
/// \sa 'meta::uncurry'
/// \ingroup lazy_composition
template <typename Fn>
using uncurry = defer<uncurry, Fn>;
} // namespace lazy
/// An invocable that reverses the order of the first two arguments.
/// \ingroup composition
template <META_TYPE_CONSTRAINT(invocable) Fn>
struct flip
{
private:
template <typename... Ts>
struct impl
{
};
template <typename A, typename B, typename... Ts>
struct impl<A, B, Ts...> : lazy::invoke<Fn, B, A, Ts...>
{
};
public:
template <typename... Ts>
using invoke = _t<impl<Ts...>>;
};
namespace lazy
{
/// \sa 'meta::flip'
/// \ingroup lazy_composition
template <typename Fn>
using flip = defer<flip, Fn>;
} // namespace lazy
/// \cond
namespace detail
{
template <typename...>
struct on_
{
};
template <typename Fn, typename... Gs>
struct on_<Fn, Gs...>
{
template <typename... Ts>
using invoke = invoke<Fn, invoke<compose<Gs...>, Ts>...>;
};
} // namespace detail
/// \endcond
/// Use as `on<Fn, Gs...>`. Creates an invocable that applies invocable \c Fn to the
/// result of applying invocable `compose<Gs...>` to all the arguments.
/// \ingroup composition
template <META_TYPE_CONSTRAINT(invocable)... Fns>
using on_ = detail::on_<Fns...>;
template <typename... Fns>
using on = on_<Fns...>;
namespace lazy
{
/// \sa 'meta::on'
/// \ingroup lazy_composition
template <typename Fn, typename G>
using on = defer<on, Fn, G>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// conditional_t
/// \cond
namespace detail
{
template <bool>
struct _cond
{
template <typename Then, typename Else>
using invoke = Then;
};
template <>
struct _cond<false>
{
template <typename Then, typename Else>
using invoke = Else;
};
} // namespace detail
/// \endcond
/// Select one type or another depending on a compile-time Boolean.
/// \ingroup logical
template <bool If, typename Then, typename Else = void>
using conditional_t = typename detail::_cond<If>::template invoke<Then, Else>;
///////////////////////////////////////////////////////////////////////////////////////////
// if_
/// \cond
namespace detail
{
#ifdef META_CONCEPT
template <typename...>
struct _if_
{
};
template <typename If>
requires integral<If>
struct _if_<If> : std::enable_if<_v<If>>
{
};
template <typename If, typename Then>
requires integral<If>
struct _if_<If, Then> : std::enable_if<_v<If>, Then>
{
};
template <typename If, typename Then, typename Else>
requires integral<If>
struct _if_<If, Then, Else> : std::conditional<_v<If>, Then, Else>
{
};
#elif defined(__clang__)
// Clang is faster with this implementation
template <typename, typename = bool>
struct _if_
{
};
template <typename If>
struct _if_<list<If>, decltype(bool(If::type::value))> : std::enable_if<If::type::value>
{
};
template <typename If, typename Then>
struct _if_<list<If, Then>, decltype(bool(If::type::value))>
: std::enable_if<If::type::value, Then>
{
};
template <typename If, typename Then, typename Else>
struct _if_<list<If, Then, Else>, decltype(bool(If::type::value))>
: std::conditional<If::type::value, Then, Else>
{
};
#else
// GCC seems to prefer this implementation
template <typename, typename = std::true_type>
struct _if_
{
};
template <typename If>
struct _if_<list<If>, bool_<If::type::value>>
{
using type = void;
};
template <typename If, typename Then>
struct _if_<list<If, Then>, bool_<If::type::value>>
{
using type = Then;
};
template <typename If, typename Then, typename Else>
struct _if_<list<If, Then, Else>, bool_<If::type::value>>
{
using type = Then;
};
template <typename If, typename Then, typename Else>
struct _if_<list<If, Then, Else>, bool_<!If::type::value>>
{
using type = Else;
};
#endif
} // namespace detail
/// \endcond
/// Select one type or another depending on a compile-time Boolean.
/// \ingroup logical
#ifdef META_CONCEPT
template <typename... Args>
using if_ = _t<detail::_if_<Args...>>;
/// Select one type or another depending on a compile-time Boolean.
/// \ingroup logical
template <bool If, typename... Args>
using if_c = _t<detail::_if_<bool_<If>, Args...>>;
#else
template <typename... Args>
using if_ = _t<detail::_if_<list<Args...>>>;
template <bool If, typename... Args>
using if_c = _t<detail::_if_<list<bool_<If>, Args...>>>;
#endif
namespace lazy
{
/// \sa 'meta::if_'
/// \ingroup lazy_logical
template <typename... Args>
using if_ = defer<if_, Args...>;
/// \sa 'meta::if_c'
/// \ingroup lazy_logical
template <bool If, typename... Args>
using if_c = if_<bool_<If>, Args...>;
} // namespace lazy
/// \cond
namespace detail
{
#ifdef META_CONCEPT
template <typename...>
struct _and_
{
};
template <>
struct _and_<> : std::true_type
{
};
template <typename B, typename... Bs>
requires integral<B> && (bool(B::type::value))
struct _and_<B, Bs...> : _and_<Bs...>
{
};
template <typename B, typename... Bs>
requires integral<B> && (!bool(B::type::value))
struct _and_<B, Bs...> : std::false_type
{
};
template <typename...>
struct _or_
{
};
template <>
struct _or_<> : std::false_type
{
};
template <typename B, typename... Bs>
requires integral<B> && (bool(B::type::value))
struct _or_<B, Bs...> : std::true_type
{
};
template <typename B, typename... Bs>
requires integral<B> && (!bool(B::type::value))
struct _or_<B, Bs...> : _or_<Bs...>
{
};
#else
template <bool>
struct _and_
{
template <typename...>
using invoke = std::true_type;
};
template <>
struct _and_<false>
{
template <typename B, typename... Bs>
using invoke = invoke<
if_c<!B::type::value, id<std::false_type>, _and_<0 == sizeof...(Bs)>>,
Bs...>;
};
template <bool>
struct _or_
{
template <typename = void>
using invoke = std::false_type;
};
template <>
struct _or_<false>
{
template <typename B, typename... Bs>
using invoke = invoke<
if_c<B::type::value, id<std::true_type>, _or_<0 == sizeof...(Bs)>>,
Bs...>;
};
#endif
} // namespace detail
/// \endcond
/// Logically negate the Boolean parameter
/// \ingroup logical
template <bool B>
using not_c = bool_<!B>;
/// Logically negate the integral constant-wrapped Boolean parameter.
/// \ingroup logical
template <META_TYPE_CONSTRAINT(integral) B>
using not_ = not_c<B::type::value>;
#if META_CXX_FOLD_EXPRESSIONS && !defined(META_WORKAROUND_GCC_UNKNOWN1)
template <bool... Bs>
META_INLINE_VAR constexpr bool and_v = (true && ... && Bs);
/// Logically AND together all the Boolean parameters
/// \ingroup logical
template <bool... Bs>
#if defined(META_WORKAROUND_MSVC_756112) || defined(META_WORKAROUND_GCC_86356)
using and_c = bool_<and_v<Bs...>>;
#else
using and_c = bool_<(true && ... && Bs)>;
#endif
#else
#if defined(META_WORKAROUND_GCC_66405)
template <bool... Bs>
using and_c = meta::bool_<
META_IS_SAME(integer_sequence<bool, true, Bs...>,
integer_sequence<bool, Bs..., true>)>;
#else
template <bool... Bs>
struct and_c
: meta::bool_<
META_IS_SAME(integer_sequence<bool, Bs...>,
integer_sequence<bool, (Bs || true)...>)>
{};
#endif
#if META_CXX_VARIABLE_TEMPLATES
template <bool... Bs>
META_INLINE_VAR constexpr bool and_v =
META_IS_SAME(integer_sequence<bool, Bs...>,
integer_sequence<bool, (Bs || true)...>);
#endif
#endif
/// Logically AND together all the integral constant-wrapped Boolean
/// parameters, \e without short-circuiting.
/// \ingroup logical
template <META_TYPE_CONSTRAINT(integral)... Bs>
using strict_and_ = and_c<Bs::type::value...>;
template <typename... Bs>
using strict_and = strict_and_<Bs...>;
/// Logically AND together all the integral constant-wrapped Boolean
/// parameters, \e with short-circuiting.
/// \ingroup logical
template <typename... Bs>
#ifdef META_CONCEPT
using and_ = _t<detail::_and_<Bs...>>;
#else
// Make a trip through defer<> to avoid CWG1430
// https://wg21.link/cwg1430
using and_ = _t<defer<detail::_and_<0 == sizeof...(Bs)>::template invoke, Bs...>>;
#endif
/// Logically OR together all the Boolean parameters
/// \ingroup logical
#if META_CXX_FOLD_EXPRESSIONS && !defined(META_WORKAROUND_GCC_UNKNOWN1)
template <bool... Bs>
META_INLINE_VAR constexpr bool or_v = (false || ... || Bs);
template <bool... Bs>
#if defined(META_WORKAROUND_MSVC_756112) || defined(META_WORKAROUND_GCC_86356)
using or_c = bool_<or_v<Bs...>>;
#else
using or_c = bool_<(false || ... || Bs)>;
#endif
#else
template <bool... Bs>
struct or_c
: meta::bool_<
!META_IS_SAME(integer_sequence<bool, Bs...>,
integer_sequence<bool, (Bs && false)...>)>
{};
#if META_CXX_VARIABLE_TEMPLATES
template <bool... Bs>
META_INLINE_VAR constexpr bool or_v =
!META_IS_SAME(integer_sequence<bool, Bs...>,
integer_sequence<bool, (Bs && false)...>);
#endif
#endif
/// Logically OR together all the integral constant-wrapped Boolean
/// parameters, \e without short-circuiting.
/// \ingroup logical
template <META_TYPE_CONSTRAINT(integral)... Bs>
using strict_or_ = or_c<Bs::type::value...>;
template <typename... Bs>
using strict_or = strict_or_<Bs...>;
/// Logically OR together all the integral constant-wrapped Boolean
/// parameters, \e with short-circuiting.
/// \ingroup logical
template <typename... Bs>
#ifdef META_CONCEPT
using or_ = _t<detail::_or_<Bs...>>;
#else
// Make a trip through defer<> to avoid CWG1430
// https://wg21.link/cwg1430
using or_ = _t<defer<detail::_or_<0 == sizeof...(Bs)>::template invoke, Bs...>>;
#endif
namespace lazy
{
/// \sa 'meta::and_'
/// \ingroup lazy_logical
template <typename... Bs>
using and_ = defer<and_, Bs...>;
/// \sa 'meta::or_'
/// \ingroup lazy_logical
template <typename... Bs>
using or_ = defer<or_, Bs...>;
/// \sa 'meta::not_'
/// \ingroup lazy_logical
template <typename B>
using not_ = defer<not_, B>;
/// \sa 'meta::strict_and'
/// \ingroup lazy_logical
template <typename... Bs>
using strict_and = defer<strict_and, Bs...>;
/// \sa 'meta::strict_or'
/// \ingroup lazy_logical
template <typename... Bs>
using strict_or = defer<strict_or, Bs...>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// fold
/// \cond
namespace detail
{
template <typename, typename, typename>
struct fold_
{
};
template <typename Fn, typename T0, typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7, typename T8, typename T9>
struct compose10_
{
template <typename X, typename Y>
using F = invoke<Fn, X, Y>;
template <typename S>
using invoke =
F<F<F<F<F<F<F<F<F<F<_t<S>, T0>, T1>, T2>, T3>, T4>, T5>, T6>, T7>, T8>, T9>;
};
#ifdef META_CONCEPT
template <typename Fn>
struct compose_
{
template <typename X, typename Y>
using F = invoke<Fn, X, Y>;
template <typename T0, typename T1, typename T2, typename T3, typename T4,
typename T5, typename T6, typename T7, typename T8, typename T9,
typename State>
using invoke =
F<F<F<F<F<F<F<F<F<F<State, T0>, T1>, T2>, T3>, T4>, T5>, T6>, T7>, T8>, T9>;
};
template <typename State, typename Fn>
struct fold_<list<>, State, Fn>
{
using type = State;
};
template <typename Head, typename... Tail, typename State, typename Fn>
requires valid<invoke, Fn, State, Head>
struct fold_<list<Head, Tail...>, State, Fn>
: fold_<list<Tail...>, invoke<Fn, State, Head>, Fn>
{
};
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename... Tail,
typename State, typename Fn>
requires valid<invoke, compose_<Fn>, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, State>
struct fold_<list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, Tail...>, State, Fn>
: fold_<list<Tail...>,
invoke<compose_<Fn>, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, State>, Fn>
{
};
#else // ^^^ Concepts / no Concepts vvv
template <typename Fn, typename T0>
struct compose1_
{
template <typename X>
using invoke = invoke<Fn, _t<X>, T0>;
};
template <typename State, typename Fn>
struct fold_<list<>, State, Fn> : State
{
};
template <typename Head, typename... Tail, typename State, typename Fn>
struct fold_<list<Head, Tail...>, State, Fn>
: fold_<list<Tail...>, lazy::invoke<compose1_<Fn, Head>, State>, Fn>
{
};
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename... Tail,
typename State, typename Fn>
struct fold_<list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, Tail...>, State, Fn>
: fold_<list<Tail...>,
lazy::invoke<compose10_<Fn, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>, State>, Fn>
{
};
#endif // META_CONCEPT
} // namespace detail
/// \endcond
/// Return a new \c meta::list constructed by doing a left fold of the list \p L using
/// binary invocable \p Fn and initial state \p State. That is, the \c State(N) for
/// the list element \c A(N) is computed by `Fn(State(N-1), A(N)) -> State(N)`.
/// \par Complexity
/// `O(N)`.
/// \ingroup transformation
template <META_TYPE_CONSTRAINT(list_like) L, typename State, META_TYPE_CONSTRAINT(invocable) Fn>
#ifdef META_CONCEPT
using fold = _t<detail::fold_<L, State, Fn>>;
#else
using fold = _t<detail::fold_<L, id<State>, Fn>>;
#endif
/// An alias for `meta::fold`.
/// \par Complexity
/// `O(N)`.
/// \ingroup transformation
template <META_TYPE_CONSTRAINT(list_like) L, typename State, META_TYPE_CONSTRAINT(invocable) Fn>
using accumulate = fold<L, State, Fn>;
namespace lazy
{
/// \sa 'meta::foldl'
/// \ingroup lazy_transformation
template <typename L, typename State, typename Fn>
using fold = defer<fold, L, State, Fn>;
/// \sa 'meta::accumulate'
/// \ingroup lazy_transformation
template <typename L, typename State, typename Fn>
using accumulate = defer<accumulate, L, State, Fn>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// reverse_fold
/// \cond
namespace detail
{
template <typename, typename, typename>
struct reverse_fold_
{
};
template <typename State, typename Fn>
struct reverse_fold_<list<>, State, Fn>
{
using type = State;
};
#ifdef META_CONCEPT
template <typename Head, typename... L, typename State, typename Fn>
requires trait<reverse_fold_<list<L...>, State, Fn>> struct reverse_fold_<
list<Head, L...>, State, Fn>
: lazy::invoke<Fn, _t<reverse_fold_<list<L...>, State, Fn>>, Head>
{
};
#else
template <typename Head, typename... Tail, typename State, typename Fn>
struct reverse_fold_<list<Head, Tail...>, State, Fn>
: lazy::invoke<compose1_<Fn, Head>, reverse_fold_<list<Tail...>, State, Fn>>
{
};
#endif
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename... Tail,
typename State, typename Fn>
struct reverse_fold_<list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, Tail...>, State, Fn>
: lazy::invoke<compose10_<Fn, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0>,
reverse_fold_<list<Tail...>, State, Fn>>
{
};
} // namespace detail
/// \endcond
/// Return a new \c meta::list constructed by doing a right fold of the list \p L using
/// binary invocable \p Fn and initial state \p State. That is, the \c State(N) for the list
/// element \c A(N) is computed by `Fn(A(N), State(N+1)) -> State(N)`.
/// \par Complexity
/// `O(N)`.
/// \ingroup transformation
template <META_TYPE_CONSTRAINT(list_like) L, typename State, META_TYPE_CONSTRAINT(invocable) Fn>
using reverse_fold = _t<detail::reverse_fold_<L, State, Fn>>;
namespace lazy
{
/// \sa 'meta::foldr'
/// \ingroup lazy_transformation
template <typename L, typename State, typename Fn>
using reverse_fold = defer<reverse_fold, L, State, Fn>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// npos
/// A special value used to indicate no matches. It equals the maximum
/// value representable by std::size_t.
/// \ingroup list
using npos = meta::size_t<std::size_t(-1)>;
///////////////////////////////////////////////////////////////////////////////////////////
// list
/// A list of types.
/// \ingroup list
template <typename... Ts>
struct list
{
using type = list;
/// \return `sizeof...(Ts)`
static constexpr std::size_t size() noexcept { return sizeof...(Ts); }
};
///////////////////////////////////////////////////////////////////////////////////////////
// size
/// An integral constant wrapper that is the size of the \c meta::list
/// \p L.
/// \ingroup list
template <META_TYPE_CONSTRAINT(list_like) L>
using size = meta::size_t<L::size()>;
namespace lazy
{
/// \sa 'meta::size'
/// \ingroup lazy_list
template <typename L>
using size = defer<size, L>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// concat
/// \cond
namespace detail
{
template <typename... Lists>
struct concat_
{
};
template <>
struct concat_<>
{
using type = list<>;
};
template <typename... L1>
struct concat_<list<L1...>>
{
using type = list<L1...>;
};
template <typename... L1, typename... L2>
struct concat_<list<L1...>, list<L2...>>
{
using type = list<L1..., L2...>;
};
template <typename... L1, typename... L2, typename... L3>
struct concat_<list<L1...>, list<L2...>, list<L3...>>
{
using type = list<L1..., L2..., L3...>;
};
template <typename... L1, typename... L2, typename... L3, typename... Rest>
struct concat_<list<L1...>, list<L2...>, list<L3...>, Rest...>
: concat_<list<L1..., L2..., L3...>, Rest...>
{
};
template <typename... L1, typename... L2, typename... L3, typename... L4,
typename... L5, typename... L6, typename... L7, typename... L8,
typename... L9, typename... L10, typename... Rest>
struct concat_<list<L1...>, list<L2...>, list<L3...>, list<L4...>, list<L5...>,
list<L6...>, list<L7...>, list<L8...>, list<L9...>, list<L10...>,
Rest...>
: concat_<list<L1..., L2..., L3..., L4..., L5..., L6..., L7..., L8..., L9..., L10...>,
Rest...>
{
};
} // namespace detail
/// \endcond
/// Concatenates several lists into a single list.
/// \pre The parameters must all be instantiations of \c meta::list.
/// \par Complexity
/// `O(L)` where `L` is the number of lists in the list of lists.
/// \ingroup transformation
template <META_TYPE_CONSTRAINT(list_like)... Ls>
using concat_ = _t<detail::concat_<Ls...>>;
template <typename... Lists>
using concat = concat_<Lists...>;
namespace lazy
{
/// \sa 'meta::concat'
/// \ingroup lazy_transformation
template <typename... Lists>
using concat = defer<concat, Lists...>;
} // namespace lazy
/// Joins a list of lists into a single list.
/// \pre The parameter must be an instantiation of \c meta::list\<T...\>
/// where each \c T is itself an instantiation of \c meta::list.
/// \par Complexity
/// `O(L)` where `L` is the number of lists in the list of
/// lists.
/// \ingroup transformation
template <META_TYPE_CONSTRAINT(list_like) ListOfLists>
using join = apply<quote<concat>, ListOfLists>;
namespace lazy
{
/// \sa 'meta::join'
/// \ingroup lazy_transformation
template <typename ListOfLists>
using join = defer<join, ListOfLists>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// transform
/// \cond
namespace detail
{
#ifdef META_CONCEPT
template <typename... Args>
struct transform_
{
};
template <typename... Ts, typename Fn>
requires invocable<Fn> && and_v<valid<invoke, Fn, Ts>...>
struct transform_<list<Ts...>, Fn>
{
using type = list<invoke<Fn, Ts>...>;
};
template <typename... Ts, typename... Us, typename Fn>
requires invocable<Fn> && and_v<valid<invoke, Fn, Ts, Us>...>
struct transform_<list<Ts...>, list<Us...>, Fn>
{
using type = list<invoke<Fn, Ts, Us>...>;
};
#else
template <typename, typename = void>
struct transform_
{
};
template <typename... Ts, typename Fn>
struct transform_<list<list<Ts...>, Fn>, void_<invoke<Fn, Ts>...>>
{
using type = list<invoke<Fn, Ts>...>;
};
template <typename... Ts0, typename... Ts1, typename Fn>
struct transform_<list<list<Ts0...>, list<Ts1...>, Fn>,
void_<invoke<Fn, Ts0, Ts1>...>>
{
using type = list<invoke<Fn, Ts0, Ts1>...>;
};
#endif
} // namespace detail
/// \endcond
/// Return a new \c meta::list constructed by transforming all the
/// elements in \p L with the unary invocable \p Fn. \c transform can
/// also be called with two lists of the same length and a binary
/// invocable, in which case it returns a new list constructed with the
/// results of calling \c Fn with each element in the lists, pairwise.
/// \par Complexity
/// `O(N)`.
/// \ingroup transformation
#ifdef META_CONCEPT
template <typename... Args>
using transform = _t<detail::transform_<Args...>>;
#else
template <typename... Args>
using transform = _t<detail::transform_<list<Args...>>>;
#endif
namespace lazy
{
/// \sa 'meta::transform'
/// \ingroup lazy_transformation
template <typename... Args>
using transform = defer<transform, Args...>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// repeat_n
/// \cond
namespace detail
{
template <typename T, std::size_t>
using first_ = T;
template <typename T, typename Ints>
struct repeat_n_c_
{
};
template <typename T, std::size_t... Is>
struct repeat_n_c_<T, index_sequence<Is...>>
{
using type = list<first_<T, Is>...>;
};
} // namespace detail
/// \endcond
/// Generate `list<T,T,T...T>` of size \p N arguments.
/// \par Complexity
/// `O(log N)`.
/// \ingroup list
template <std::size_t N, typename T = void>
using repeat_n_c = _t<detail::repeat_n_c_<T, make_index_sequence<N>>>;
/// Generate `list<T,T,T...T>` of size \p N arguments.
/// \par Complexity
/// `O(log N)`.
/// \ingroup list
template <META_TYPE_CONSTRAINT(integral) N, typename T = void>
using repeat_n = repeat_n_c<N::type::value, T>;
namespace lazy
{
/// \sa 'meta::repeat_n'
/// \ingroup lazy_list
template <typename N, typename T = void>
using repeat_n = defer<repeat_n, N, T>;
/// \sa 'meta::repeat_n_c'
/// \ingroup lazy_list
template <std::size_t N, typename T = void>
using repeat_n_c = defer<repeat_n, meta::size_t<N>, T>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// at
/// \cond
namespace detail
{
#if META_HAS_TYPE_PACK_ELEMENT && !defined(META_DOXYGEN_INVOKED)
template <typename L, std::size_t N, typename = void>
struct at_
{
};
template <typename... Ts, std::size_t N>
struct at_<list<Ts...>, N, void_<__type_pack_element<N, Ts...>>>
{
using type = __type_pack_element<N, Ts...>;
};
#else
template <typename VoidPtrs>
struct at_impl_;
template <typename... VoidPtrs>
struct at_impl_<list<VoidPtrs...>>
{
static nil_ eval(...);
template <typename T, typename... Us>
static T eval(VoidPtrs..., T *, Us *...);
};
template <typename L, std::size_t N>
struct at_
{
};
template <typename... Ts, std::size_t N>
struct at_<list<Ts...>, N>
: decltype(at_impl_<repeat_n_c<N, void *>>::eval(static_cast<id<Ts> *>(nullptr)...))
{
};
#endif // META_HAS_TYPE_PACK_ELEMENT
} // namespace detail
/// \endcond
/// Return the \p N th element in the \c meta::list \p L.
/// \par Complexity
/// Amortized `O(1)`.
/// \ingroup list
template <META_TYPE_CONSTRAINT(list_like) L, std::size_t N>
using at_c = _t<detail::at_<L, N>>;
/// Return the \p N th element in the \c meta::list \p L.
/// \par Complexity
/// Amortized `O(1)`.
/// \ingroup list
template <META_TYPE_CONSTRAINT(list_like) L, META_TYPE_CONSTRAINT(integral) N>
using at = at_c<L, N::type::value>;
namespace lazy
{
/// \sa 'meta::at'
/// \ingroup lazy_list
template <typename L, typename N>
using at = defer<at, L, N>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// drop
/// \cond
namespace detail
{
///////////////////////////////////////////////////////////////////////////////////////
/// drop_impl_
template <typename VoidPtrs>
struct drop_impl_
{
static nil_ eval(...);
};
template <typename... VoidPtrs>
struct drop_impl_<list<VoidPtrs...>>
{
static nil_ eval(...);
template <typename... Ts>
static id<list<Ts...>> eval(VoidPtrs..., id<Ts> *...);
};
template <>
struct drop_impl_<list<>>
{
template <typename... Ts>
static id<list<Ts...>> eval(id<Ts> *...);
};
template <typename L, std::size_t N>
struct drop_
{
};
template <typename... Ts, std::size_t N>
struct drop_<list<Ts...>, N>
#if META_CXX_VARIABLE_TEMPLATES
: decltype(drop_impl_<repeat_n_c<N, void *>>::eval(detail::nullptr_v<id<Ts>>...))
#else
: decltype(drop_impl_<repeat_n_c<N, void *>>::eval(detail::_nullptr_v<id<Ts>>()...))
#endif
{
};
} // namespace detail
/// \endcond
/// Return a new \c meta::list by removing the first \p N elements from \p L.
/// \par Complexity
/// `O(1)`.
/// \ingroup transformation
template <META_TYPE_CONSTRAINT(list_like) L, std::size_t N>
using drop_c = _t<detail::drop_<L, N>>;
/// Return a new \c meta::list by removing the first \p N elements from \p L.
/// \par Complexity
/// `O(1)`.
/// \ingroup transformation
template <META_TYPE_CONSTRAINT(list_like) L, META_TYPE_CONSTRAINT(integral) N>
using drop = drop_c<L, N::type::value>;
namespace lazy
{
/// \sa 'meta::drop'
/// \ingroup lazy_transformation
template <typename L, typename N>
using drop = defer<drop, L, N>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// front
/// \cond
namespace detail
{
template <typename L>
struct front_
{
};
template <typename Head, typename... Tail>
struct front_<list<Head, Tail...>>
{
using type = Head;
};
} // namespace detail
/// \endcond
/// Return the first element in \c meta::list \p L.
/// \par Complexity
/// `O(1)`.
/// \ingroup list
template <META_TYPE_CONSTRAINT(list_like) L>
using front = _t<detail::front_<L>>;
namespace lazy
{
/// \sa 'meta::front'
/// \ingroup lazy_list
template <typename L>
using front = defer<front, L>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// back
/// \cond
namespace detail
{
template <typename L>
struct back_
{
};
template <typename Head, typename... Tail>
struct back_<list<Head, Tail...>>
{
using type = at_c<list<Head, Tail...>, sizeof...(Tail)>;
};
} // namespace detail
/// \endcond
/// Return the last element in \c meta::list \p L.
/// \par Complexity
/// Amortized `O(1)`.
/// \ingroup list
template <META_TYPE_CONSTRAINT(list_like) L>
using back = _t<detail::back_<L>>;
namespace lazy
{
/// \sa 'meta::back'
/// \ingroup lazy_list
template <typename L>
using back = defer<back, L>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// push_front
/// Return a new \c meta::list by adding the element \c T to the front of \p L.
/// \par Complexity
/// `O(1)`.
/// \ingroup transformation
template <META_TYPE_CONSTRAINT(list_like) L, typename... Ts>
using push_front = apply<bind_front<quote<list>, Ts...>, L>;
namespace lazy
{
/// \sa 'meta::push_front'
/// \ingroup lazy_transformation
template <typename... Ts>
using push_front = defer<push_front, Ts...>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// pop_front
/// \cond
namespace detail
{
template <typename L>
struct pop_front_
{
};
template <typename Head, typename... L>
struct pop_front_<list<Head, L...>>
{
using type = list<L...>;
};
} // namespace detail
/// \endcond
/// Return a new \c meta::list by removing the first element from the
/// front of \p L.
/// \par Complexity
/// `O(1)`.
/// \ingroup transformation
template <META_TYPE_CONSTRAINT(list_like) L>
using pop_front = _t<detail::pop_front_<L>>;
namespace lazy
{
/// \sa 'meta::pop_front'
/// \ingroup lazy_transformation
template <typename L>
using pop_front = defer<pop_front, L>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// push_back
/// Return a new \c meta::list by adding the element \c T to the back of \p L.
/// \par Complexity
/// `O(1)`.
/// \note \c pop_back not provided because it cannot be made to meet the
/// complexity guarantees one would expect.
/// \ingroup transformation
template <META_TYPE_CONSTRAINT(list_like) L, typename... Ts>
using push_back = apply<bind_back<quote<list>, Ts...>, L>;
namespace lazy
{
/// \sa 'meta::push_back'
/// \ingroup lazy_transformation
template <typename... Ts>
using push_back = defer<push_back, Ts...>;
} // namespace lazy
/// \cond
namespace detail
{
template <typename T, typename U>
using min_ = if_<less<U, T>, U, T>;
template <typename T, typename U>
using max_ = if_<less<U, T>, T, U>;
} // namespace detail
/// \endcond
/// An integral constant wrapper around the minimum of `Ts::type::value...`
/// \ingroup math
template <META_TYPE_CONSTRAINT(integral)... Ts>
using min_ = fold<pop_front<list<Ts...>>, front<list<Ts...>>, quote<detail::min_>>;
template <typename... Ts>
using min = min_<Ts...>;
/// An integral constant wrapper around the maximum of `Ts::type::value...`
/// \ingroup math
template <META_TYPE_CONSTRAINT(integral)... Ts>
using max_ = fold<pop_front<list<Ts...>>, front<list<Ts...>>, quote<detail::max_>>;
template <typename... Ts>
using max = max_<Ts...>;
namespace lazy
{
/// \sa 'meta::min'
/// \ingroup lazy_math
template <typename... Ts>
using min = defer<min, Ts...>;
/// \sa 'meta::max'
/// \ingroup lazy_math
template <typename... Ts>
using max = defer<max, Ts...>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// empty
/// An Boolean integral constant wrapper around \c true if \p L is an
/// empty type list; \c false, otherwise.
/// \par Complexity
/// `O(1)`.
/// \ingroup list
template <META_TYPE_CONSTRAINT(list_like) L>
using empty = bool_<0 == size<L>::type::value>;
namespace lazy
{
/// \sa 'meta::empty'
/// \ingroup lazy_list
template <typename L>
using empty = defer<empty, L>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// pair
/// A list with exactly two elements
/// \ingroup list
template <typename F, typename S>
using pair = list<F, S>;
/// Retrieve the first element of the \c pair \p Pair
/// \ingroup list
template <typename Pair>
using first = front<Pair>;
/// Retrieve the first element of the \c pair \p Pair
/// \ingroup list
template <typename Pair>
using second = front<pop_front<Pair>>;
namespace lazy
{
/// \sa 'meta::first'
/// \ingroup lazy_list
template <typename Pair>
using first = defer<first, Pair>;
/// \sa 'meta::second'
/// \ingroup lazy_list
template <typename Pair>
using second = defer<second, Pair>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// find_index
/// \cond
namespace detail
{
// With thanks to Peter Dimov:
constexpr std::size_t find_index_i_(bool const *const first, bool const *const last,
std::size_t N = 0)
{
return first == last ? npos::value
: *first ? N : find_index_i_(first + 1, last, N + 1);
}
template <typename L, typename T>
struct find_index_
{
};
template <typename V>
struct find_index_<list<>, V>
{
using type = npos;
};
template <typename... T, typename V>
struct find_index_<list<T...>, V>
{
#ifdef META_WORKAROUND_LLVM_28385
static constexpr bool s_v[sizeof...(T)] = {META_IS_SAME(T, V)...};
#else
static constexpr bool s_v[] = {META_IS_SAME(T, V)...};
#endif
using type = size_t<find_index_i_(s_v, s_v + sizeof...(T))>;
};
} // namespace detail
/// \endcond
/// Finds the index of the first occurrence of the type \p T within the list \p L.
/// Returns `#meta::npos` if the type \p T was not found.
/// \par Complexity
/// `O(N)`.
/// \ingroup query
/// \sa `meta::npos`
template <META_TYPE_CONSTRAINT(list_like) L, typename T>
using find_index = _t<detail::find_index_<L, T>>;
namespace lazy
{
/// \sa 'meta::find_index'
/// \ingroup lazy_query
template <typename L, typename T>
using find_index = defer<find_index, L, T>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// reverse_find_index
/// \cond
namespace detail
{
// With thanks to Peter Dimov:
constexpr std::size_t reverse_find_index_i_(bool const *const first,
bool const *const last, std::size_t N)
{
return first == last
? npos::value
: *(last - 1) ? N - 1 : reverse_find_index_i_(first, last - 1, N - 1);
}
template <typename L, typename T>
struct reverse_find_index_
{
};
template <typename V>
struct reverse_find_index_<list<>, V>
{
using type = npos;
};
template <typename... T, typename V>
struct reverse_find_index_<list<T...>, V>
{
#ifdef META_WORKAROUND_LLVM_28385
static constexpr bool s_v[sizeof...(T)] = {META_IS_SAME(T, V)...};
#else
static constexpr bool s_v[] = {META_IS_SAME(T, V)...};
#endif
using type = size_t<reverse_find_index_i_(s_v, s_v + sizeof...(T), sizeof...(T))>;
};
} // namespace detail
/// \endcond
/// Finds the index of the last occurrence of the type \p T within the
/// list \p L. Returns `#meta::npos` if the type \p T was not found.
/// \par Complexity
/// `O(N)`.
/// \ingroup query
/// \sa `#meta::npos`
template <META_TYPE_CONSTRAINT(list_like) L, typename T>
using reverse_find_index = _t<detail::reverse_find_index_<L, T>>;
namespace lazy
{
/// \sa 'meta::reverse_find_index'
/// \ingroup lazy_query
template <typename L, typename T>
using reverse_find_index = defer<reverse_find_index, L, T>;
} // namespace lazy
////////////////////////////////////////////////////////////////////////////////////
// find
/// Return the tail of the list \p L starting at the first occurrence of
/// \p T, if any such element exists; the empty list, otherwise.
/// \par Complexity
/// `O(N)`.
/// \ingroup query
template <META_TYPE_CONSTRAINT(list_like) L, typename T>
using find = drop<L, min<find_index<L, T>, size<L>>>;
namespace lazy
{
/// \sa 'meta::find'
/// \ingroup lazy_query
template <typename L, typename T>
using find = defer<find, L, T>;
} // namespace lazy
////////////////////////////////////////////////////////////////////////////////////
// reverse_find
/// \cond
namespace detail
{
template <typename L, typename T, typename State = list<>>
struct reverse_find_
{
};
template <typename T, typename State>
struct reverse_find_<list<>, T, State>
{
using type = State;
};
template <typename Head, typename... L, typename T, typename State>
struct reverse_find_<list<Head, L...>, T, State> : reverse_find_<list<L...>, T, State>
{
};
template <typename... L, typename T, typename State>
struct reverse_find_<list<T, L...>, T, State>
: reverse_find_<list<L...>, T, list<T, L...>>
{
};
} // namespace detail
/// \endcond
/// Return the tail of the list \p L starting at the last occurrence of \p T, if any such
/// element exists; the empty list, otherwise.
/// \par Complexity
/// `O(N)`.
/// \ingroup query
template <META_TYPE_CONSTRAINT(list_like) L, typename T>
using reverse_find = drop<L, min<reverse_find_index<L, T>, size<L>>>;
namespace lazy
{
/// \sa 'meta::rfind'
/// \ingroup lazy_query
template <typename L, typename T>
using reverse_find = defer<reverse_find, L, T>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// find_if
/// \cond
namespace detail
{
#ifdef META_CONCEPT
template <typename L, typename Fn>
struct find_if_
{
};
template <typename Fn>
struct find_if_<list<>, Fn>
{
using type = list<>;
};
template <typename Head, typename... L, typename Fn>
requires integral<invoke<Fn, Head>>
struct find_if_<list<Head, L...>, Fn>
: if_<invoke<Fn, Head>, id<list<Head, L...>>, find_if_<list<L...>, Fn>>
{
};
#else
constexpr bool const *find_if_i_(bool const *const begin, bool const *const end)
{
return begin == end || *begin ? begin : find_if_i_(begin + 1, end);
}
template <typename L, typename Fn, typename = void>
struct find_if_
{
};
template <typename Fn>
struct find_if_<list<>, Fn>
{
using type = list<>;
};
template <typename... L, typename Fn>
struct find_if_<list<L...>, Fn,
void_<integer_sequence<bool, bool(invoke<Fn, L>::type::value)...>>>
{
#ifdef META_WORKAROUND_LLVM_28385
static constexpr bool s_v[sizeof...(L)] = {invoke<Fn, L>::type::value...};
#else
static constexpr bool s_v[] = {invoke<Fn, L>::type::value...};
#endif
using type =
drop_c<list<L...>, detail::find_if_i_(s_v, s_v + sizeof...(L)) - s_v>;
};
#endif
} // namespace detail
/// \endcond
/// Return the tail of the list \p L starting at the first element `A`
/// such that `invoke<Fn, A>::%value` is \c true, if any such element
/// exists; the empty list, otherwise.
/// \par Complexity
/// `O(N)`.
/// \ingroup query
template <META_TYPE_CONSTRAINT(list_like) L, META_TYPE_CONSTRAINT(invocable) Fn>
using find_if = _t<detail::find_if_<L, Fn>>;
namespace lazy
{
/// \sa 'meta::find_if'
/// \ingroup lazy_query
template <typename L, typename Fn>
using find_if = defer<find_if, L, Fn>;
} // namespace lazy
////////////////////////////////////////////////////////////////////////////////////
// reverse_find_if
/// \cond
namespace detail
{
#ifdef META_CONCEPT
template <typename L, typename Fn, typename State = list<>>
struct reverse_find_if_
{
};
template <typename Fn, typename State>
struct reverse_find_if_<list<>, Fn, State>
{
using type = State;
};
template <typename Head, typename... L, typename Fn, typename State>
requires integral<invoke<Fn, Head>>
struct reverse_find_if_<list<Head, L...>, Fn, State>
: reverse_find_if_<list<L...>, Fn, if_<invoke<Fn, Head>, list<Head, L...>, State>>
{
};
#else
constexpr bool const *reverse_find_if_i_(bool const *const begin, bool const *const pos,
bool const *const end)
{
return begin == pos
? end
: *(pos - 1) ? pos - 1 : reverse_find_if_i_(begin, pos - 1, end);
}
template <typename L, typename Fn, typename = void>
struct reverse_find_if_
{
};
template <typename Fn>
struct reverse_find_if_<list<>, Fn>
{
using type = list<>;
};
template <typename... L, typename Fn>
struct reverse_find_if_<
list<L...>, Fn,
void_<integer_sequence<bool, bool(invoke<Fn, L>::type::value)...>>>
{
#ifdef META_WORKAROUND_LLVM_28385
static constexpr bool s_v[sizeof...(L)] = {invoke<Fn, L>::type::value...};
#else
static constexpr bool s_v[] = {invoke<Fn, L>::type::value...};
#endif
using type =
drop_c<list<L...>, detail::reverse_find_if_i_(s_v, s_v + sizeof...(L),
s_v + sizeof...(L)) -
s_v>;
};
#endif
} // namespace detail
/// \endcond
/// Return the tail of the list \p L starting at the last element `A`
/// such that `invoke<Fn, A>::%value` is \c true, if any such element
/// exists; the empty list, otherwise.
/// \par Complexity
/// `O(N)`.
/// \ingroup query
template <META_TYPE_CONSTRAINT(list_like) L, META_TYPE_CONSTRAINT(invocable) Fn>
using reverse_find_if = _t<detail::reverse_find_if_<L, Fn>>;
namespace lazy
{
/// \sa 'meta::rfind_if'
/// \ingroup lazy_query
template <typename L, typename Fn>
using reverse_find_if = defer<reverse_find_if, L, Fn>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// replace
/// \cond
namespace detail
{
template <typename L, typename T, typename U>
struct replace_
{
};
template <typename... L, typename T, typename U>
struct replace_<list<L...>, T, U>
{
using type = list<if_c<META_IS_SAME(T, L), U, L>...>;
};
} // namespace detail
/// \endcond
/// Return a new \c meta::list where all instances of type \p T have
/// been replaced with \p U.
/// \par Complexity
/// `O(N)`.
/// \ingroup transformation
template <META_TYPE_CONSTRAINT(list_like) L, typename T, typename U>
using replace = _t<detail::replace_<L, T, U>>;
namespace lazy
{
/// \sa 'meta::replace'
/// \ingroup lazy_transformation
template <typename L, typename T, typename U>
using replace = defer<replace, T, U>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// replace_if
/// \cond
namespace detail
{
#ifdef META_CONCEPT
template <typename L, typename C, typename U>
struct replace_if_
{
};
template <typename... L, typename C, typename U>
requires and_v<integral<invoke<C, L>>...>
struct replace_if_<list<L...>, C, U>
{
using type = list<if_<invoke<C, L>, U, L>...>;
};
#else
template <typename L, typename C, typename U, typename = void>
struct replace_if_
{
};
template <typename... L, typename C, typename U>
struct replace_if_<list<L...>, C, U,
void_<integer_sequence<bool, bool(invoke<C, L>::type::value)...>>>
{
using type = list<if_<invoke<C, L>, U, L>...>;
};
#endif
} // namespace detail
/// \endcond
/// Return a new \c meta::list where all elements \c A of the list \p L
/// for which `invoke<C,A>::%value` is \c true have been replaced with
/// \p U.
/// \par Complexity
/// `O(N)`.
/// \ingroup transformation
template <META_TYPE_CONSTRAINT(list_like) L, typename C, typename U>
using replace_if = _t<detail::replace_if_<L, C, U>>;
namespace lazy
{
/// \sa 'meta::replace_if'
/// \ingroup lazy_transformation
template <typename L, typename C, typename U>
using replace_if = defer<replace_if, C, U>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////
// count
namespace detail
{
template <typename, typename>
struct count_
{
};
#if (defined(META_CONCEPT) || META_CXX_VARIABLE_TEMPLATES) && META_CXX_FOLD_EXPRESSIONS
template <typename... Ts, typename T>
struct count_<list<Ts...>, T>
{
using type = meta::size_t<((std::size_t)META_IS_SAME(T, Ts) + ...)>;
};
#else
constexpr std::size_t count_i_(bool const *const begin, bool const *const end,
std::size_t n)
{
return begin == end ? n : detail::count_i_(begin + 1, end, n + *begin);
}
template <typename T>
struct count_<list<>, T>
{
using type = meta::size_t<0>;
};
template <typename... L, typename T>
struct count_<list<L...>, T>
{
#ifdef META_WORKAROUND_LLVM_28385
static constexpr bool s_v[sizeof...(L)] = {META_IS_SAME(T, L)...};
#else
static constexpr bool s_v[] = {META_IS_SAME(T, L)...};
#endif
using type = meta::size_t<detail::count_i_(s_v, s_v + sizeof...(L), 0u)>;
};
#endif
} // namespace detail
/// Count the number of times a type \p T appears in the list \p L.
/// \par Complexity
/// `O(N)`.
/// \ingroup query
template <META_TYPE_CONSTRAINT(list_like) L, typename T>
using count = _t<detail::count_<L, T>>;
namespace lazy
{
/// \sa `meta::count`
/// \ingroup lazy_query
template <typename L, typename T>
using count = defer<count, L, T>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////
// count_if
namespace detail
{
#if defined(META_CONCEPT) && META_CXX_FOLD_EXPRESSIONS
template <typename, typename>
struct count_if_
{
};
template <typename... Ts, typename Fn>
requires (integral<invoke<Fn, Ts>> && ...)
struct count_if_<list<Ts...>, Fn>
{
using type = meta::size_t<((std::size_t)(bool)_v<invoke<Fn, Ts>> + ...)>;
};
#else
template <typename L, typename Fn, typename = void>
struct count_if_
{
};
template <typename Fn>
struct count_if_<list<>, Fn>
{
using type = meta::size_t<0>;
};
template <typename... L, typename Fn>
struct count_if_<list<L...>, Fn,
void_<integer_sequence<bool, bool(invoke<Fn, L>::type::value)...>>>
{
#if META_CXX_FOLD_EXPRESSIONS
using type = meta::size_t<((std::size_t)(bool)invoke<Fn, L>::type::value + ...)>;
#else
#ifdef META_WORKAROUND_LLVM_28385
static constexpr bool s_v[sizeof...(L)] = {invoke<Fn, L>::type::value...};
#else
static constexpr bool s_v[] = {invoke<Fn, L>::type::value...};
#endif
using type = meta::size_t<detail::count_i_(s_v, s_v + sizeof...(L), 0u)>;
#endif // META_CXX_FOLD_EXPRESSIONS
};
#endif // META_CONCEPT
} // namespace detail
/// Count the number of times the predicate \p Fn evaluates to true for all the elements in
/// the list \p L.
/// \par Complexity
/// `O(N)`.
/// \ingroup query
template <META_TYPE_CONSTRAINT(list_like) L, META_TYPE_CONSTRAINT(invocable) Fn>
using count_if = _t<detail::count_if_<L, Fn>>;
namespace lazy
{
/// \sa `meta::count_if`
/// \ingroup lazy_query
template <typename L, typename Fn>
using count_if = defer<count_if, L, Fn>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// filter
/// \cond
namespace detail
{
template <typename Pred>
struct filter_
{
template <typename A>
using invoke = if_c<invoke<Pred, A>::type::value, list<A>, list<>>;
};
} // namespace detail
/// \endcond
/// Returns a new meta::list where only those elements of \p L that satisfy the
/// Callable \p Pred such that `invoke<Pred,A>::%value` is \c true are present.
/// That is, those elements that don't satisfy the \p Pred are "removed".
/// \par Complexity
/// `O(N)`.
/// \ingroup transformation
template <typename L, typename Pred>
using filter = join<transform<L, detail::filter_<Pred>>>;
namespace lazy
{
/// \sa 'meta::filter'
/// \ingroup lazy_transformation
template <typename L, typename Fn>
using filter = defer<filter, L, Fn>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// static_const
///\cond
namespace detail
{
template <typename T>
struct static_const
{
static constexpr T value{};
};
// Avoid potential ODR violations with global objects:
template <typename T>
constexpr T static_const<T>::value;
} // namespace detail
///\endcond
///////////////////////////////////////////////////////////////////////////////////////////
// for_each
/// \cond
namespace detail
{
struct for_each_fn
{
template <class Fn, class... Args>
constexpr auto operator()(list<Args...>, Fn f) const -> Fn
{
return (void)std::initializer_list<int>{((void)f(Args{}), 0)...}, f;
}
};
} // namespace detail
/// \endcond
#if META_CXX_INLINE_VARIABLES
/// `for_each(L, Fn)` calls the \p Fn for each
/// argument in the \p L.
/// \ingroup runtime
inline constexpr detail::for_each_fn for_each{};
#else
///\cond
namespace
{
/// \endcond
/// `for_each(List, UnaryFunction)` calls the \p UnaryFunction for each
/// argument in the \p List.
/// \ingroup runtime
constexpr auto &&for_each = detail::static_const<detail::for_each_fn>::value;
/// \cond
}
/// \endcond
#endif
///////////////////////////////////////////////////////////////////////////////////////////
// transpose
/// Given a list of lists of types \p ListOfLists, transpose the elements from the lists.
/// \par Complexity
/// `O(N * M)`, where `N` is the size of the outer list, and
/// `M` is the size of the inner lists.
/// \ingroup transformation
template <META_TYPE_CONSTRAINT(list_like) ListOfLists>
using transpose = fold<ListOfLists, repeat_n<size<front<ListOfLists>>, list<>>,
bind_back<quote<transform>, quote<push_back>>>;
namespace lazy
{
/// \sa 'meta::transpose'
/// \ingroup lazy_transformation
template <typename ListOfLists>
using transpose = defer<transpose, ListOfLists>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// zip_with
/// Given a list of lists of types \p ListOfLists and an invocable \p Fn, construct a new
/// list by calling \p Fn with the elements from the lists pairwise.
/// \par Complexity
/// `O(N * M)`, where `N` is the size of the outer list, and
/// `M` is the size of the inner lists.
/// \ingroup transformation
template <META_TYPE_CONSTRAINT(invocable) Fn, META_TYPE_CONSTRAINT(list_like) ListOfLists>
using zip_with = transform<transpose<ListOfLists>, uncurry<Fn>>;
namespace lazy
{
/// \sa 'meta::zip_with'
/// \ingroup lazy_transformation
template <typename Fn, typename ListOfLists>
using zip_with = defer<zip_with, Fn, ListOfLists>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// zip
/// Given a list of lists of types \p ListOfLists, construct a new list by grouping the
/// elements from the lists pairwise into `meta::list`s.
/// \par Complexity
/// `O(N * M)`, where `N` is the size of the outer list, and `M`
/// is the size of the inner lists.
/// \ingroup transformation
template <META_TYPE_CONSTRAINT(list_like) ListOfLists>
using zip = transpose<ListOfLists>;
namespace lazy
{
/// \sa 'meta::zip'
/// \ingroup lazy_transformation
template <typename ListOfLists>
using zip = defer<zip, ListOfLists>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// as_list
/// \cond
namespace detail
{
template <typename T>
using uncvref_t = _t<std::remove_cv<_t<std::remove_reference<T>>>>;
// Indirection here needed to avoid Core issue 1430
// https://wg21.link/cwg1430
template <typename Sequence>
struct as_list_ : lazy::invoke<uncurry<quote<list>>, Sequence>
{
};
} // namespace detail
/// \endcond
/// Turn a type into an instance of \c meta::list in a way determined by
/// \c meta::apply.
/// \ingroup list
template <typename Sequence>
using as_list = _t<detail::as_list_<detail::uncvref_t<Sequence>>>;
namespace lazy
{
/// \sa 'meta::as_list'
/// \ingroup lazy_list
template <typename Sequence>
using as_list = defer<as_list, Sequence>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// reverse
/// \cond
namespace detail
{
template <typename L, typename State = list<>>
struct reverse_ : lazy::fold<L, State, quote<push_front>>
{
};
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5,
typename T6, typename T7, typename T8, typename T9, typename... Ts,
typename... Us>
struct reverse_<list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, Ts...>, list<Us...>>
: reverse_<list<Ts...>, list<T9, T8, T7, T6, T5, T4, T3, T2, T1, T0, Us...>>
{
};
}
/// \endcond
/// Return a new \c meta::list by reversing the elements in the list \p L.
/// \par Complexity
/// `O(N)`.
/// \ingroup transformation
template <META_TYPE_CONSTRAINT(list_like) L>
using reverse = _t<detail::reverse_<L>>;
namespace lazy
{
/// \sa 'meta::reverse'
/// \ingroup lazy_transformation
template <typename L>
using reverse = defer<reverse, L>;
} // namespace lazy
/// Logically negate the result of invocable \p Fn.
/// \ingroup trait
template <META_TYPE_CONSTRAINT(invocable) Fn>
using not_fn = compose<quote<not_>, Fn>;
namespace lazy
{
/// \sa 'meta::not_fn'
/// \ingroup lazy_trait
template <typename Fn>
using not_fn = defer<not_fn, Fn>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// all_of
/// A Boolean integral constant wrapper around \c true if `invoke<Fn, A>::%value` is \c true
/// for all elements \c A in \c meta::list \p L; \c false, otherwise.
/// \par Complexity
/// `O(N)`.
/// \ingroup query
template <META_TYPE_CONSTRAINT(list_like) L, META_TYPE_CONSTRAINT(invocable) Fn>
using all_of = empty<find_if<L, not_fn<Fn>>>;
namespace lazy
{
/// \sa 'meta::all_of'
/// \ingroup lazy_query
template <typename L, typename Fn>
using all_of = defer<all_of, L, Fn>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// any_of
/// A Boolean integral constant wrapper around \c true if `invoke<Fn, A>::%value` is
/// \c true for any element \c A in \c meta::list \p L; \c false, otherwise.
/// \par Complexity
/// `O(N)`.
/// \ingroup query
template <META_TYPE_CONSTRAINT(list_like) L, META_TYPE_CONSTRAINT(invocable) Fn>
using any_of = not_<empty<find_if<L, Fn>>>;
namespace lazy
{
/// \sa 'meta::any_of'
/// \ingroup lazy_query
template <typename L, typename Fn>
using any_of = defer<any_of, L, Fn>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// none_of
/// A Boolean integral constant wrapper around \c true if `invoke<Fn, A>::%value` is
/// \c false for all elements \c A in \c meta::list \p L; \c false, otherwise.
/// \par Complexity
/// `O(N)`.
/// \ingroup query
template <META_TYPE_CONSTRAINT(list_like) L, META_TYPE_CONSTRAINT(invocable) Fn>
using none_of = empty<find_if<L, Fn>>;
namespace lazy
{
/// \sa 'meta::none_of'
/// \ingroup lazy_query
template <typename L, META_TYPE_CONSTRAINT(invocable) Fn>
using none_of = defer<none_of, L, Fn>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// in
/// A Boolean integral constant wrapper around \c true if there is at least one occurrence
/// of \p T in \p L.
/// \par Complexity
/// `O(N)`.
/// \ingroup query
template <META_TYPE_CONSTRAINT(list_like) L, typename T>
using in = not_<empty<find<L, T>>>;
namespace lazy
{
/// \sa 'meta::in'
/// \ingroup lazy_query
template <typename L, typename T>
using in = defer<in, L, T>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// inherit
/// \cond
namespace detail
{
template <typename L>
struct inherit_
{
};
template <typename... L>
struct inherit_<list<L...>> : L...
{
using type = inherit_;
};
} // namespace detail
/// \endcond
/// A type that inherits from all the types in the list
/// \pre The types in the list must be unique
/// \pre All the types in the list must be non-final class types
/// \ingroup datatype
template <META_TYPE_CONSTRAINT(list_like) L>
using inherit = meta::_t<detail::inherit_<L>>;
namespace lazy
{
/// \sa 'meta::inherit'
/// \ingroup lazy_datatype
template <typename L>
using inherit = defer<inherit, L>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// unique
/// \cond
namespace detail
{
template <typename Set, typename T>
struct in_
{
};
template <typename... Set, typename T>
struct in_<list<Set...>, T> : bool_<META_IS_BASE_OF(id<T>, inherit<list<id<Set>...>>)>
{
};
template <typename Set, typename T>
struct insert_back_
{
};
template <typename... Set, typename T>
struct insert_back_<list<Set...>, T>
{
using type = if_<in_<list<Set...>, T>, list<Set...>, list<Set..., T>>;
};
} // namespace detail
/// \endcond
/// Return a new \c meta::list where all duplicate elements have been removed.
/// \par Complexity
/// `O(N^2)`.
/// \ingroup transformation
template <META_TYPE_CONSTRAINT(list_like) L>
using unique = fold<L, list<>, quote_trait<detail::insert_back_>>;
namespace lazy
{
/// \sa 'meta::unique'
/// \ingroup lazy_transformation
template <typename L>
using unique = defer<unique, L>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// partition
/// \cond
namespace detail
{
template <typename Fn>
struct partition_
{
#ifdef META_CONCEPT
template <typename, typename>
#else
template <typename, typename, typename = void>
#endif
struct impl
{
};
template <typename... Yes, typename... No, typename A>
#ifdef META_CONCEPT
requires integral<invoke<Fn, A>>
struct impl<pair<list<Yes...>, list<No...>>, A>
#else
struct impl<pair<list<Yes...>, list<No...>>, A,
void_<bool_<invoke<Fn, A>::type::value>>>
#endif
{
using type = if_<meta::invoke<Fn, A>, pair<list<Yes..., A>, list<No...>>,
pair<list<Yes...>, list<No..., A>>>;
};
template <typename State, typename A>
using invoke = _t<impl<State, A>>;
};
} // namespace detail
/// \endcond
/// Returns a pair of lists, where the elements of \p L that satisfy the
/// invocable \p Fn such that `invoke<Fn,A>::%value` is \c true are present in the
/// first list and the rest are in the second.
/// \par Complexity
/// `O(N)`.
/// \ingroup transformation
template <META_TYPE_CONSTRAINT(list_like) L, META_TYPE_CONSTRAINT(invocable) Fn>
using partition = fold<L, pair<list<>, list<>>, detail::partition_<Fn>>;
namespace lazy
{
/// \sa 'meta::partition'
/// \ingroup lazy_transformation
template <typename L, typename Fn>
using partition = defer<partition, L, Fn>;
} // namespace lazy
///////////////////////////////////////////////////////////////////////////////////////////
// sort
/// \cond
namespace detail
{
template <META_TYPE_CONSTRAINT(invocable) Fn, typename A, typename B, typename... Ts>
using part_ = partition<list<B, Ts...>, bind_back<Fn, A>>;
#ifdef META_CONCEPT
template <typename L, typename Fn>
requires list_like<L> && invocable<Fn>
#else
template <typename, typename, typename = void>
#endif
struct sort_
{
};
template <typename Fn>
struct sort_<list<>, Fn>
{
using type = list<>;
};
template <typename A, typename Fn>
struct sort_<list<A>, Fn>
{
using type = list<A>;
};
template <typename A, typename B, typename... Ts, typename Fn>
#ifdef META_CONCEPT
requires trait<sort_<first<part_<Fn, A, B, Ts...>>, Fn>> &&
trait<sort_<second<part_<Fn, A, B, Ts...>>, Fn>>
struct sort_<list<A, B, Ts...>, Fn>
#else
struct sort_<
list<A, B, Ts...>, Fn,
void_<_t<sort_<first<part_<Fn, A, B, Ts...>>, Fn>>>>
#endif
{
using P = part_<Fn, A, B, Ts...>;
using type = concat<_t<sort_<first<P>, Fn>>, list<A>, _t<sort_<second<P>, Fn>>>;
};
} // namespace detail
/// \endcond
// clang-format off
/// Return a new \c meta::list that is sorted according to invocable predicate \p Fn.
/// \par Complexity
/// Expected: `O(N log N)`
/// Worst case: `O(N^2)`.
/// \code
/// using L0 = list<char[5], char[3], char[2], char[6], char[1], char[5], char[10]>;
/// using L1 = meta::sort<L0, lambda<_a, _b, lazy::less<lazy::sizeof_<_a>, lazy::sizeof_<_b>>>>;
/// static_assert(std::is_same_v<L1, list<char[1], char[2], char[3], char[5], char[5], char[6], char[10]>>, "");
/// \endcode
/// \ingroup transformation
// clang-format on
template <META_TYPE_CONSTRAINT(list_like) L, META_TYPE_CONSTRAINT(invocable) Fn>
using sort = _t<detail::sort_<L, Fn>>;
namespace lazy
{
/// \sa 'meta::sort'
/// \ingroup lazy_transformation
template <typename L, typename Fn>
using sort = defer<sort, L, Fn>;
} // namespace lazy
////////////////////////////////////////////////////////////////////////////
// lambda_
/// \cond
namespace detail
{
template <typename T, int = 0>
struct protect_;
template <typename, int = 0>
struct vararg_;
template <typename T, int = 0>
struct is_valid_;
// Returns which branch to evaluate
template <typename If, typename... Ts>
#ifdef META_CONCEPT
using lazy_if_ = lazy::_t<defer<_if_, If, protect_<Ts>...>>;
#else
using lazy_if_ = lazy::_t<defer<_if_, list<If, protect_<Ts>...>>>;
#endif
template <typename A, typename T, typename Fn, typename Ts>
struct subst1_
{
using type = list<list<T>>;
};
template <typename T, typename Fn, typename Ts>
struct subst1_<Fn, T, Fn, Ts>
{
using type = list<>;
};
template <typename A, typename T, typename Fn, typename Ts>
struct subst1_<vararg_<A>, T, Fn, Ts>
{
using type = list<Ts>;
};
template <typename As, typename Ts>
using substitutions_ = push_back<
join<transform<
concat<As, repeat_n_c<size<Ts>{} + 2 - size<As>{}, back<As>>>,
concat<Ts, repeat_n_c<2, back<As>>>,
bind_back<quote_trait<subst1_>, back<As>, drop_c<Ts, size<As>{} - 2>>>>,
list<back<As>>>;
#if 0//def META_CONCEPT
template <list_like As, list_like Ts>
requires (_v<size<Ts>> + 2 >= _v<size<As>>)
using substitutions = substitutions_<As, Ts>;
#else // ^^^ concepts / no concepts vvv
template <typename As, typename Ts>
using substitutions =
#ifdef META_WORKAROUND_MSVC_702792
invoke<if_c<(size<Ts>::value + 2 >= size<As>::value), quote<substitutions_>>, As,
Ts>;
#else // ^^^ workaround ^^^ / vvv no workaround vvv
invoke<if_c<(size<Ts>{} + 2 >= size<As>{}), quote<substitutions_>>, As, Ts>;
#endif // META_WORKAROUND_MSVC_702792
#endif // META_CONCEPT
template <typename T>
struct is_vararg_ : std::false_type
{
};
template <typename T>
struct is_vararg_<vararg_<T>> : std::true_type
{
};
template <META_TYPE_CONSTRAINT(list_like) Tags>
using is_variadic_ = is_vararg_<at<push_front<Tags, void>, dec<size<Tags>>>>;
template <META_TYPE_CONSTRAINT(list_like) Tags, bool IsVariadic = is_variadic_<Tags>::value>
struct lambda_;
// Non-variadic lambda implementation
template <typename... As>
struct lambda_<list<As...>, false>
{
private:
static constexpr std::size_t arity = sizeof...(As) - 1;
using Tags = list<As...>; // Includes the lambda body as the last arg!
using Fn = back<Tags>;
template <typename T, META_TYPE_CONSTRAINT(list_like) Args>
struct impl;
template <typename T, META_TYPE_CONSTRAINT(list_like) Args>
using lazy_impl_ = lazy::_t<defer<impl, T, protect_<Args>>>;
#if 0//def META_CONCEPT
template <typename, list_like>
#else
template <typename, typename, typename = void>
#endif
struct subst_
{
};
template <template <typename...> class C, typename... Ts, typename Args>
#if 0//def META_CONCEPT
requires valid<C, _t<impl<Ts, Args>>...> struct subst_<defer<C, Ts...>, Args>
#else
struct subst_<defer<C, Ts...>, Args, void_<C<_t<impl<Ts, Args>>...>>>
#endif
{
using type = C<_t<impl<Ts, Args>>...>;
};
template <typename T, template <T...> class C, T... Is, typename Args>
#if 0//def META_CONCEPT
requires valid_i<T, C, Is...> struct subst_<defer_i<T, C, Is...>, Args>
#else
struct subst_<defer_i<T, C, Is...>, Args, void_<C<Is...>>>
#endif
{
using type = C<Is...>;
};
template <typename T, META_TYPE_CONSTRAINT(list_like) Args>
struct impl : if_c<(reverse_find_index<Tags, T>() != npos()),
lazy::at<Args, reverse_find_index<Tags, T>>, id<T>>
{
};
template <typename T, typename Args>
struct impl<protect_<T>, Args>
{
using type = T;
};
template <typename T, typename Args>
struct impl<is_valid_<T>, Args>
{
using type = is_trait<impl<T, Args>>;
};
template <typename If, typename... Ts, typename Args>
struct impl<defer<if_, If, Ts...>, Args> // Short-circuit if_
: impl<lazy_impl_<lazy_if_<If, Ts...>, Args>, Args>
{
};
template <typename B, typename... Bs, typename Args>
struct impl<defer<and_, B, Bs...>, Args> // Short-circuit and_
: impl<lazy_impl_<lazy_if_<B, lazy::and_<Bs...>, protect_<std::false_type>>, Args>,
Args>
{
};
template <typename B, typename... Bs, typename Args>
struct impl<defer<or_, B, Bs...>, Args> // Short-circuit or_
: impl<lazy_impl_<lazy_if_<B, protect_<std::true_type>, lazy::or_<Bs...>>, Args>,
Args>
{
};
template <template <typename...> class C, typename... Ts, typename Args>
struct impl<defer<C, Ts...>, Args> : subst_<defer<C, Ts...>, Args>
{
};
template <typename T, template <T...> class C, T... Is, typename Args>
struct impl<defer_i<T, C, Is...>, Args> : subst_<defer_i<T, C, Is...>, Args>
{
};
template <template <typename...> class C, typename... Ts, typename Args>
struct impl<C<Ts...>, Args> : subst_<defer<C, Ts...>, Args>
{
};
template <typename... Ts, typename Args>
struct impl<lambda_<list<Ts...>, false>, Args>
{
using type = compose<uncurry<lambda_<list<As..., Ts...>, false>>,
curry<bind_front<quote<concat>, Args>>>;
};
template <typename... Bs, typename Args>
struct impl<lambda_<list<Bs...>, true>, Args>
{
using type = compose<typename lambda_<list<As..., Bs...>, true>::thunk,
bind_front<quote<concat>, transform<Args, quote<list>>>,
curry<bind_front<quote<substitutions>, list<Bs...>>>>;
};
public:
template <typename... Ts>
#ifdef META_CONCEPT
requires (sizeof...(Ts) == arity) using invoke = _t<impl<Fn, list<Ts..., Fn>>>;
#else
using invoke = _t<if_c<sizeof...(Ts) == arity, impl<Fn, list<Ts..., Fn>>>>;
#endif
};
// Lambda with variadic placeholder (broken out due to less efficient compile-time
// resource usage)
template <typename... As>
struct lambda_<list<As...>, true>
{
private:
template <META_TYPE_CONSTRAINT(list_like) T, bool IsVar>
friend struct lambda_;
using Tags = list<As...>; // Includes the lambda body as the last arg!
template <typename T, META_TYPE_CONSTRAINT(list_like) Args>
struct impl;
template <META_TYPE_CONSTRAINT(list_like) Args>
using eval_impl_ = bind_back<quote_trait<impl>, Args>;
template <typename T, META_TYPE_CONSTRAINT(list_like) Args>
using lazy_impl_ = lazy::_t<defer<impl, T, protect_<Args>>>;
template <template <typename...> class C, META_TYPE_CONSTRAINT(list_like) Args,
META_TYPE_CONSTRAINT(list_like) Ts>
using try_subst_ = apply<quote<C>, join<transform<Ts, eval_impl_<Args>>>>;
#if 0//def META_CONCEPT
template <typename, list_like>
#else
template <typename, typename, typename = void>
#endif
struct subst_
{
};
template <template <typename...> class C, typename... Ts, typename Args>
#if 0//def META_CONCEPT
requires is_true<try_subst_<C, Args, list<Ts...>>> struct subst_<defer<C, Ts...>, Args>
#else
struct subst_<defer<C, Ts...>, Args, void_<try_subst_<C, Args, list<Ts...>>>>
#endif
{
using type = list<try_subst_<C, Args, list<Ts...>>>;
};
template <typename T, template <T...> class C, T... Is, typename Args>
#if 0//def META_CONCEPT
requires valid_i<T, C, Is...> struct subst_<defer_i<T, C, Is...>, Args>
#else
struct subst_<defer_i<T, C, Is...>, Args, void_<C<Is...>>>
#endif
{
using type = list<C<Is...>>;
};
template <typename T, META_TYPE_CONSTRAINT(list_like) Args>
struct impl : if_c<(reverse_find_index<Tags, T>() != npos()),
lazy::at<Args, reverse_find_index<Tags, T>>, id<list<T>>>
{
};
template <typename T, typename Args>
struct impl<protect_<T>, Args>
{
using type = list<T>;
};
template <typename T, typename Args>
struct impl<is_valid_<T>, Args>
{
using type = list<is_trait<impl<T, Args>>>;
};
template <typename If, typename... Ts, typename Args>
struct impl<defer<if_, If, Ts...>, Args> // Short-circuit if_
: impl<lazy_impl_<lazy_if_<If, Ts...>, Args>, Args>
{
};
template <typename B, typename... Bs, typename Args>
struct impl<defer<and_, B, Bs...>, Args> // Short-circuit and_
: impl<lazy_impl_<lazy_if_<B, lazy::and_<Bs...>, protect_<std::false_type>>, Args>,
Args>
{
};
template <typename B, typename... Bs, typename Args>
struct impl<defer<or_, B, Bs...>, Args> // Short-circuit or_
: impl<lazy_impl_<lazy_if_<B, protect_<std::true_type>, lazy::or_<Bs...>>, Args>,
Args>
{
};
template <template <typename...> class C, typename... Ts, typename Args>
struct impl<defer<C, Ts...>, Args> : subst_<defer<C, Ts...>, Args>
{
};
template <typename T, template <T...> class C, T... Is, typename Args>
struct impl<defer_i<T, C, Is...>, Args> : subst_<defer_i<T, C, Is...>, Args>
{
};
template <template <typename...> class C, typename... Ts, typename Args>
struct impl<C<Ts...>, Args> : subst_<defer<C, Ts...>, Args>
{
};
template <typename... Bs, bool IsVar, typename Args>
struct impl<lambda_<list<Bs...>, IsVar>, Args>
{
using type =
list<compose<typename lambda_<list<As..., Bs...>, true>::thunk,
bind_front<quote<concat>, Args>,
curry<bind_front<quote<substitutions>, list<Bs...>>>>>;
};
struct thunk
{
template <typename S, typename R = _t<impl<back<Tags>, S>>>
#ifdef META_CONCEPT
requires (_v<size<R>> == 1) using invoke = front<R>;
#else
using invoke = if_c<size<R>{} == 1, front<R>>;
#endif
};
public:
template <typename... Ts>
using invoke = invoke<thunk, substitutions<Tags, list<Ts...>>>;
};
} // namespace detail
/// \endcond
///////////////////////////////////////////////////////////////////////////////////////////
// lambda
/// For creating anonymous Invocables.
/// \code
/// using L = lambda<_a, _b, std::pair<_b, std::pair<_a, _a>>>;
/// using P = invoke<L, int, short>;
/// static_assert(std::is_same_v<P, std::pair<short, std::pair<int, int>>>, "");
/// \endcode
/// \ingroup trait
template <typename... Ts>
#ifdef META_CONCEPT
requires (sizeof...(Ts) > 0) using lambda = detail::lambda_<list<Ts...>>;
#else
using lambda = if_c<(sizeof...(Ts) > 0), detail::lambda_<list<Ts...>>>;
#endif
///////////////////////////////////////////////////////////////////////////////////////////
// is_valid
/// For testing whether a deferred computation will succeed in a \c let or a \c lambda.
/// \ingroup trait
template <typename T>
using is_valid = detail::is_valid_<T>;
///////////////////////////////////////////////////////////////////////////////////////////
// vararg
/// For defining variadic placeholders.
template <typename T>
using vararg = detail::vararg_<T>;
///////////////////////////////////////////////////////////////////////////////////////////
// protect
/// For preventing the evaluation of a nested `defer`ed computation in a \c let or
/// \c lambda expression.
template <typename T>
using protect = detail::protect_<T>;
///////////////////////////////////////////////////////////////////////////////////////////
// var
/// For use when defining local variables in \c meta::let expressions
/// \sa `meta::let`
template <typename Tag, typename Value>
struct var;
/// \cond
namespace detail
{
template <typename...>
struct let_
{
};
template <typename Fn>
struct let_<Fn>
{
using type = lazy::invoke<lambda<Fn>>;
};
template <typename Tag, typename Value, typename... Rest>
struct let_<var<Tag, Value>, Rest...>
{
using type = lazy::invoke<lambda<Tag, _t<let_<Rest...>>>, Value>;
};
} // namespace detail
/// \endcond
/// A lexically scoped expression with local variables.
///
/// \code
/// template <typename T, typename L>
/// using find_index_ = let<
/// var<_a, L>,
/// var<_b, lazy::find<_a, T>>,
/// lazy::if_<
/// std::is_same<_b, list<>>,
/// meta::npos,
/// lazy::minus<lazy::size<_a>, lazy::size<_b>>>>;
/// static_assert(find_index_<int, list<short, int, float>>{} == 1, "");
/// static_assert(find_index_<double, list<short, int, float>>{} == meta::npos{}, "");
/// \endcode
/// \ingroup trait
template <typename... As>
using let = _t<_t<detail::let_<As...>>>;
namespace lazy
{
/// \sa `meta::let`
/// \ingroup lazy_trait
template <typename... As>
using let = defer<let, As...>;
} // namespace lazy
// Some argument placeholders for use in \c lambda expressions.
/// \ingroup trait
inline namespace placeholders
{
// regular placeholders:
struct _a;
struct _b;
struct _c;
struct _d;
struct _e;
struct _f;
struct _g;
struct _h;
struct _i;
// variadic placeholders:
using _args = vararg<void>;
using _args_a = vararg<_a>;
using _args_b = vararg<_b>;
using _args_c = vararg<_c>;
} // namespace placeholders
///////////////////////////////////////////////////////////////////////////////////////////
// cartesian_product
/// \cond
namespace detail
{
template <typename M2, typename M>
struct cartesian_product_fn
{
template <typename X>
struct lambda0
{
template <typename Xs>
using lambda1 = list<push_front<Xs, X>>;
using type = join<transform<M2, quote<lambda1>>>;
};
using type = join<transform<M, quote_trait<lambda0>>>;
};
} // namespace detail
/// \endcond
/// Given a list of lists \p ListOfLists, return a new list of lists that is the Cartesian
/// Product. Like the `sequence` function from the Haskell Prelude.
/// \par Complexity
/// `O(N * M)`, where `N` is the size of the outer list, and
/// `M` is the size of the inner lists.
/// \ingroup transformation
template <META_TYPE_CONSTRAINT(list_like) ListOfLists>
using cartesian_product =
reverse_fold<ListOfLists, list<list<>>, quote_trait<detail::cartesian_product_fn>>;
namespace lazy
{
/// \sa 'meta::cartesian_product'
/// \ingroup lazy_transformation
template <typename ListOfLists>
using cartesian_product = defer<cartesian_product, ListOfLists>;
} // namespace lazy
/// \cond
///////////////////////////////////////////////////////////////////////////////////////////
// add_const_if
namespace detail
{
template <bool>
struct add_const_if
{
template <typename T>
using invoke = T const;
};
template <>
struct add_const_if<false>
{
template <typename T>
using invoke = T;
};
} // namespace detail
template <bool If>
using add_const_if_c = detail::add_const_if<If>;
template <META_TYPE_CONSTRAINT(integral) If>
using add_const_if = add_const_if_c<If::type::value>;
/// \endcond
/// \cond
///////////////////////////////////////////////////////////////////////////////////////////
// const_if
template <bool If, typename T>
using const_if_c = typename add_const_if_c<If>::template invoke<T>;
template <typename If, typename T>
using const_if = typename add_const_if<If>::template invoke<T>;
/// \endcond
/// \cond
namespace detail
{
template <typename State, typename Ch>
using atoi_ = if_c<(Ch::value >= '0' && Ch::value <= '9'),
std::integral_constant<typename State::value_type,
State::value * 10 + (Ch::value - '0')>>;
}
/// \endcond
inline namespace literals
{
/// A user-defined literal that generates objects of type \c meta::size_t.
/// \ingroup integral
template <char... Chs>
constexpr fold<list<char_<Chs>...>, meta::size_t<0>, quote<detail::atoi_>>
operator"" _z()
{
return {};
}
} // namespace literals
} // namespace meta
/// \cond
// Non-portable forward declarations of standard containers
#ifndef META_NO_STD_FORWARD_DECLARATIONS
#if defined(__apple_build_version__) || (defined(__clang__) && __clang_major__ < 6)
META_BEGIN_NAMESPACE_STD
META_BEGIN_NAMESPACE_VERSION
template <class>
class META_TEMPLATE_VIS allocator;
template <class, class>
struct META_TEMPLATE_VIS pair;
template <class>
struct META_TEMPLATE_VIS hash;
template <class>
struct META_TEMPLATE_VIS less;
template <class>
struct META_TEMPLATE_VIS equal_to;
template <class>
struct META_TEMPLATE_VIS char_traits;
#if defined(_GLIBCXX_USE_CXX11_ABI) && _GLIBCXX_USE_CXX11_ABI
inline namespace __cxx11 {
#endif
template <class, class, class>
class META_TEMPLATE_VIS basic_string;
#if defined(_GLIBCXX_USE_CXX11_ABI) && _GLIBCXX_USE_CXX11_ABI
}
#endif
META_END_NAMESPACE_VERSION
META_BEGIN_NAMESPACE_CONTAINER
#if defined(__GLIBCXX__)
inline namespace __cxx11 {
#endif
template <class, class>
class META_TEMPLATE_VIS list;
#if defined(__GLIBCXX__)
}
#endif
template <class, class>
class META_TEMPLATE_VIS forward_list;
template <class, class>
class META_TEMPLATE_VIS vector;
template <class, class>
class META_TEMPLATE_VIS deque;
template <class, class, class, class>
class META_TEMPLATE_VIS map;
template <class, class, class, class>
class META_TEMPLATE_VIS multimap;
template <class, class, class>
class META_TEMPLATE_VIS set;
template <class, class, class>
class META_TEMPLATE_VIS multiset;
template <class, class, class, class, class>
class META_TEMPLATE_VIS unordered_map;
template <class, class, class, class, class>
class META_TEMPLATE_VIS unordered_multimap;
template <class, class, class, class>
class META_TEMPLATE_VIS unordered_set;
template <class, class, class, class>
class META_TEMPLATE_VIS unordered_multiset;
template <class, class>
class META_TEMPLATE_VIS queue;
template <class, class, class>
class META_TEMPLATE_VIS priority_queue;
template <class, class>
class META_TEMPLATE_VIS stack;
META_END_NAMESPACE_CONTAINER
META_END_NAMESPACE_STD
namespace meta
{
namespace detail
{
template <typename T, typename A = std::allocator<T>>
using std_list = std::list<T, A>;
template <typename T, typename A = std::allocator<T>>
using std_forward_list = std::forward_list<T, A>;
template <typename T, typename A = std::allocator<T>>
using std_vector = std::vector<T, A>;
template <typename T, typename A = std::allocator<T>>
using std_deque = std::deque<T, A>;
template <typename T, typename C = std::char_traits<T>, typename A = std::allocator<T>>
using std_basic_string = std::basic_string<T, C, A>;
template <typename K, typename V, typename C = std::less<K>,
typename A = std::allocator<std::pair<K const, V>>>
using std_map = std::map<K, V, C, A>;
template <typename K, typename V, typename C = std::less<K>,
typename A = std::allocator<std::pair<K const, V>>>
using std_multimap = std::multimap<K, V, C, A>;
template <typename K, typename C = std::less<K>, typename A = std::allocator<K>>
using std_set = std::set<K, C, A>;
template <typename K, typename C = std::less<K>, typename A = std::allocator<K>>
using std_multiset = std::multiset<K, C, A>;
template <typename K, typename V, typename H = std::hash<K>,
typename C = std::equal_to<K>,
typename A = std::allocator<std::pair<K const, V>>>
using std_unordered_map = std::unordered_map<K, V, H, C, A>;
template <typename K, typename V, typename H = std::hash<K>,
typename C = std::equal_to<K>,
typename A = std::allocator<std::pair<K const, V>>>
using std_unordered_multimap = std::unordered_multimap<K, V, H, C, A>;
template <typename K, typename H = std::hash<K>, typename C = std::equal_to<K>,
typename A = std::allocator<K>>
using std_unordered_set = std::unordered_set<K, H, C, A>;
template <typename K, typename H = std::hash<K>, typename C = std::equal_to<K>,
typename A = std::allocator<K>>
using std_unordered_multiset = std::unordered_multiset<K, H, C, A>;
template <typename T, typename C = std_deque<T>>
using std_queue = std::queue<T, C>;
template <typename T, typename C = std_vector<T>,
class D = std::less<typename C::value_type>>
using std_priority_queue = std::priority_queue<T, C, D>;
template <typename T, typename C = std_deque<T>>
using std_stack = std::stack<T, C>;
} // namespace detail
template <>
struct quote<::std::list> : quote<detail::std_list>
{
};
template <>
struct quote<::std::deque> : quote<detail::std_deque>
{
};
template <>
struct quote<::std::forward_list> : quote<detail::std_forward_list>
{
};
template <>
struct quote<::std::vector> : quote<detail::std_vector>
{
};
template <>
struct quote<::std::basic_string> : quote<detail::std_basic_string>
{
};
template <>
struct quote<::std::map> : quote<detail::std_map>
{
};
template <>
struct quote<::std::multimap> : quote<detail::std_multimap>
{
};
template <>
struct quote<::std::set> : quote<detail::std_set>
{
};
template <>
struct quote<::std::multiset> : quote<detail::std_multiset>
{
};
template <>
struct quote<::std::unordered_map> : quote<detail::std_unordered_map>
{
};
template <>
struct quote<::std::unordered_multimap> : quote<detail::std_unordered_multimap>
{
};
template <>
struct quote<::std::unordered_set> : quote<detail::std_unordered_set>
{
};
template <>
struct quote<::std::unordered_multiset> : quote<detail::std_unordered_multiset>
{
};
template <>
struct quote<::std::queue> : quote<detail::std_queue>
{
};
template <>
struct quote<::std::priority_queue> : quote<detail::std_priority_queue>
{
};
template <>
struct quote<::std::stack> : quote<detail::std_stack>
{
};
} // namespace meta
#endif
#endif
/// \endcond
#ifdef __clang__
#pragma GCC diagnostic pop
#endif
#endif
|
0 | repos/range-v3/include/std | repos/range-v3/include/std/detail/associated_types.hpp | // Range v3 library
//
// Copyright Eric Niebler 2013-2014, 2016-present
// Copyright Casey Carter 2016
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_V3_STD_DETAIL_ASSOCIATED_TYPES_HPP
#define RANGES_V3_STD_DETAIL_ASSOCIATED_TYPES_HPP
#include <climits>
#include <cstdint>
#include <range/v3/detail/config.hpp>
#include <range/v3/detail/prologue.hpp>
namespace ranges
{
/// \addtogroup group-iterator
/// @{
////////////////////////////////////////////////////////////////////////////////////////
/// \cond
namespace detail
{
struct nil_
{};
template<typename T, typename...>
using always_ = T;
#if defined(_MSC_VER) && !defined(__clang__) && !defined(__EDG__)
// MSVC laughs at your silly micro-optimizations and implements
// conditional_t, enable_if_t, is_object_v, and is_integral_v in the
// compiler.
using std::conditional_t;
using std::enable_if;
using std::enable_if_t;
#else // ^^^ MSVC / not MSVC vvv
template<bool>
struct _cond
{
template<typename, typename U>
using invoke = U;
};
template<>
struct _cond<true>
{
template<typename T, typename>
using invoke = T;
};
template<bool B, typename T, typename U>
using conditional_t = typename _cond<B>::template invoke<T, U>;
template<bool>
struct enable_if
{};
template<>
struct enable_if<true>
{
template<typename T>
using invoke = T;
};
template<bool B, typename T = void>
using enable_if_t = typename enable_if<B>::template invoke<T>;
#ifndef __clang__
// NB: insufficient for MSVC, which (non-conformingly) allows function
// pointers to implicitly convert to void*.
void is_objptr_(void const volatile *);
// std::is_object, optimized for compile time.
template<typename T>
constexpr bool is_object_(long)
{
return false;
}
template<typename T>
constexpr bool is_object_(int, T * (*q)(T &) = nullptr, T * p = nullptr,
decltype(detail::is_objptr_(q(*p))) * = nullptr)
{
return (void)p, (void)q, true;
}
#endif // !__clang__
template<typename T>
constexpr bool is_integral_(...)
{
return false;
}
template<typename T, T = 1>
constexpr bool is_integral_(long)
{
return true;
}
#if defined(__cpp_nontype_template_parameter_class) && \
__cpp_nontype_template_parameter_class > 0
template<typename T>
constexpr bool is_integral_(int, int T::* = nullptr)
{
return false;
}
#endif
#endif // detect MSVC
template<typename T>
struct with_difference_type_
{
using difference_type = T;
};
template<typename T>
using difference_result_t =
decltype(std::declval<T const &>() - std::declval<T const &>());
template<typename, typename = void>
struct incrementable_traits_2_
{};
template<typename T>
struct incrementable_traits_2_<
T,
#if defined(_MSC_VER) && !defined(__clang__) && !defined(__EDG__)
std::enable_if_t<std::is_integral_v<difference_result_t<T>>>>
#elif defined(RANGES_WORKAROUND_GCC_91923)
std::enable_if_t<std::is_integral<difference_result_t<T>>::value>>
#else
always_<void, int[is_integral_<difference_result_t<T>>(0)]>>
#endif // detect MSVC
{
using difference_type = std::make_signed_t<difference_result_t<T>>;
};
template<typename T, typename = void>
struct incrementable_traits_1_ : incrementable_traits_2_<T>
{};
template<typename T>
struct incrementable_traits_1_<T *>
#ifdef __clang__
: conditional_t<__is_object(T), with_difference_type_<std::ptrdiff_t>, nil_>
#elif defined(_MSC_VER) && !defined(__EDG__)
: conditional_t<std::is_object_v<T>, with_difference_type_<std::ptrdiff_t>, nil_>
#else // ^^^ MSVC / not MSVC vvv
: conditional_t<is_object_<T>(0), with_difference_type_<std::ptrdiff_t>, nil_>
#endif // detect MSVC
{};
template<typename T>
struct incrementable_traits_1_<T, always_<void, typename T::difference_type>>
{
using difference_type = typename T::difference_type;
};
} // namespace detail
/// \endcond
template<typename T>
struct incrementable_traits : detail::incrementable_traits_1_<T>
{};
template<typename T>
struct incrementable_traits<T const> : incrementable_traits<T>
{};
/// \cond
namespace detail
{
#ifdef __clang__
template<typename T, bool = __is_object(T)>
#elif defined(_MSC_VER) && !defined(__EDG__)
template<typename T, bool = std::is_object_v<T>>
#else // ^^^ MSVC / not MSVC vvv
template<typename T, bool = is_object_<T>(0)>
#endif // detect MSVC
struct with_value_type_
{};
template<typename T>
struct with_value_type_<T, true>
{
using value_type = T;
};
template<typename T>
struct with_value_type_<T const, true>
{
using value_type = T;
};
template<typename T>
struct with_value_type_<T volatile, true>
{
using value_type = T;
};
template<typename T>
struct with_value_type_<T const volatile, true>
{
using value_type = T;
};
template<typename, typename = void>
struct readable_traits_2_
{};
template<typename T>
struct readable_traits_2_<T, always_<void, typename T::element_type>>
: with_value_type_<typename T::element_type>
{};
template<typename T, typename = void>
struct readable_traits_1_ : readable_traits_2_<T>
{};
template<typename T>
struct readable_traits_1_<T[]> : with_value_type_<T>
{};
template<typename T, std::size_t N>
struct readable_traits_1_<T[N]> : with_value_type_<T>
{};
template<typename T>
struct readable_traits_1_<T *> : detail::with_value_type_<T>
{};
template<typename T>
struct readable_traits_1_<T, always_<void, typename T::value_type>>
: with_value_type_<typename T::value_type>
{};
} // namespace detail
/// \endcond
////////////////////////////////////////////////////////////////////////////////////////
// Not to spec:
// * For class types with both member value_type and element_type, value_type is
// preferred (see ericniebler/stl2#299).
template<typename T>
struct indirectly_readable_traits : detail::readable_traits_1_<T>
{};
template<typename T>
struct indirectly_readable_traits<T const> : indirectly_readable_traits<T>
{};
/// \cond
namespace detail
{
template<typename D = std::ptrdiff_t>
struct std_output_iterator_traits
{
using iterator_category = std::output_iterator_tag;
using difference_type = D;
using value_type = void;
using reference = void;
using pointer = void;
};
// For testing whether a particular instantiation of std::iterator_traits
// is user-specified or not.
#if defined(_MSVC_STL_UPDATE) && defined(__cpp_lib_concepts) && _MSVC_STL_UPDATE >= 201908L
template<typename I>
inline constexpr bool is_std_iterator_traits_specialized_v =
!std::_Is_from_primary<std::iterator_traits<I>>;
#else
#if defined(__GLIBCXX__)
template<typename I>
char (&is_std_iterator_traits_specialized_impl_(std::__iterator_traits<I> *))[2];
template<typename I>
char is_std_iterator_traits_specialized_impl_(void *);
#elif defined(_LIBCPP_VERSION)
// In older versions of libc++, the base template inherits from std::__iterator_traits<typename, bool>.
template<template<typename, bool> class IteratorTraitsBase, typename I, bool B>
char (&libcpp_iterator_traits_base_impl(IteratorTraitsBase<I, B> *))[2];
template<template<typename, bool> class IteratorTraitsBase, typename I>
char libcpp_iterator_traits_base_impl(void *);
// In newer versions, the base template has only one template parameter and provides the
// __primary_template typedef which aliases the iterator_traits specialization.
template<template<typename> class, typename I>
char (&libcpp_iterator_traits_base_impl(typename std::iterator_traits<I>::__primary_template *))[2];
template<template<typename> class, typename I>
char libcpp_iterator_traits_base_impl(void *);
template<typename I>
auto is_std_iterator_traits_specialized_impl_(std::iterator_traits<I>* traits)
-> decltype(libcpp_iterator_traits_base_impl<std::__iterator_traits, I>(traits));
#elif defined(_MSVC_STL_VERSION) || defined(_IS_WRS)
template<typename I>
char (&is_std_iterator_traits_specialized_impl_(
std::_Iterator_traits_base<I> *))[2];
template<typename I>
char is_std_iterator_traits_specialized_impl_(void *);
#else
template<typename I>
char (&is_std_iterator_traits_specialized_impl_(void *))[2];
#endif
template<typename, typename T>
char (&is_std_iterator_traits_specialized_impl_(std::iterator_traits<T *> *))[2];
template<typename I>
RANGES_INLINE_VAR constexpr bool is_std_iterator_traits_specialized_v =
1 == sizeof(is_std_iterator_traits_specialized_impl_<I>(
static_cast<std::iterator_traits<I> *>(nullptr)));
#endif
// The standard iterator_traits<T *> specialization(s) do not count
// as user-specialized. This will no longer be necessary in C++20.
// This helps with `T volatile*` and `void *`.
template<typename T>
RANGES_INLINE_VAR constexpr bool is_std_iterator_traits_specialized_v<T *> =
false;
} // namespace detail
/// \endcond
} // namespace ranges
#include <range/v3/detail/epilogue.hpp>
#endif
|
0 | repos/range-v3 | repos/range-v3/example/for_each_sequence.cpp | // Range v3 library
//
// Copyright Jeff Garland 2017
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
///[for_each_sequence]
// Use the for_each to print from various containers
// output
// vector: 1 2 3 4 5 6
// array: 1 2 3 4 5 6
// list: 1 2 3 4 5 6
// fwd_list: 1 2 3 4 5 6
// deque: 1 2 3 4 5 6
#include <array>
#include <deque>
#include <forward_list>
#include <iostream>
#include <list>
#include <queue>
#include <range/v3/algorithm/for_each.hpp> // specific includes
#include <stack>
#include <vector>
using std::cout;
auto print = [](int i) { cout << i << ' '; };
int
main()
{
cout << "vector: ";
std::vector<int> v{1, 2, 3, 4, 5, 6};
ranges::for_each(v, print); // 1 2 3 4 5 6
cout << "\narray: ";
std::array<int, 6> a{1, 2, 3, 4, 5, 6};
ranges::for_each(a, print);
cout << "\nlist: ";
std::list<int> ll{1, 2, 3, 4, 5, 6};
ranges::for_each(ll, print);
cout << "\nfwd_list: ";
std::forward_list<int> fl{1, 2, 3, 4, 5, 6};
ranges::for_each(fl, print);
cout << "\ndeque: ";
std::deque<int> d{1, 2, 3, 4, 5, 6};
ranges::for_each(d, print);
cout << '\n';
}
///[for_each_sequence]
|
0 | repos/range-v3 | repos/range-v3/example/calendar.cpp | // Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#include <range/v3/detail/config.hpp>
#if RANGES_CXX_RETURN_TYPE_DEDUCTION >= RANGES_CXX_RETURN_TYPE_DEDUCTION_14 && \
RANGES_CXX_GENERIC_LAMBDAS >= RANGES_CXX_GENERIC_LAMBDAS_14
///[calendar]
// Usage:
// calendar 2015
//
// Output:
/*
January February March
1 2 3 1 2 3 4 5 6 7 1 2 3 4 5 6 7
4 5 6 7 8 9 10 8 9 10 11 12 13 14 8 9 10 11 12 13 14
11 12 13 14 15 16 17 15 16 17 18 19 20 21 15 16 17 18 19 20 21
18 19 20 21 22 23 24 22 23 24 25 26 27 28 22 23 24 25 26 27 28
25 26 27 28 29 30 31 29 30 31
April May June
1 2 3 4 1 2 1 2 3 4 5 6
5 6 7 8 9 10 11 3 4 5 6 7 8 9 7 8 9 10 11 12 13
12 13 14 15 16 17 18 10 11 12 13 14 15 16 14 15 16 17 18 19 20
19 20 21 22 23 24 25 17 18 19 20 21 22 23 21 22 23 24 25 26 27
26 27 28 29 30 24 25 26 27 28 29 30 28 29 30
31
July August September
1 2 3 4 1 1 2 3 4 5
5 6 7 8 9 10 11 2 3 4 5 6 7 8 6 7 8 9 10 11 12
12 13 14 15 16 17 18 9 10 11 12 13 14 15 13 14 15 16 17 18 19
19 20 21 22 23 24 25 16 17 18 19 20 21 22 20 21 22 23 24 25 26
26 27 28 29 30 31 23 24 25 26 27 28 29 27 28 29 30
30 31
October November December
1 2 3 1 2 3 4 5 6 7 1 2 3 4 5
4 5 6 7 8 9 10 8 9 10 11 12 13 14 6 7 8 9 10 11 12
11 12 13 14 15 16 17 15 16 17 18 19 20 21 13 14 15 16 17 18 19
18 19 20 21 22 23 24 22 23 24 25 26 27 28 20 21 22 23 24 25 26
25 26 27 28 29 30 31 29 30 27 28 29 30 31
// */
// Credits:
// Thanks to H. S. Teoh for the article that served as the
// inspiration for this example:
// <http://wiki.dlang.org/Component_programming_with_ranges>
// Thanks to github's Arzar for bringing date::week_number
// to my attention.
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/format.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/program_options.hpp>
#include <algorithm>
#include <cstddef>
#include <functional>
#include <iostream>
#include <range/v3/action/join.hpp>
#include <range/v3/algorithm/copy.hpp>
#include <range/v3/algorithm/for_each.hpp>
#include <range/v3/algorithm/mismatch.hpp>
#include <range/v3/core.hpp>
#include <range/v3/iterator/stream_iterators.hpp>
#include <range/v3/view/all.hpp>
#include <range/v3/view/chunk.hpp>
#include <range/v3/view/chunk_by.hpp>
#include <range/v3/view/concat.hpp>
#include <range/v3/view/iota.hpp>
#include <range/v3/view/join.hpp>
#include <range/v3/view/repeat_n.hpp>
#include <range/v3/view/single.hpp>
#include <range/v3/view/take.hpp>
#include <range/v3/view/transform.hpp>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
namespace po = boost::program_options;
namespace greg = boost::gregorian;
using date = greg::date;
using day = greg::date_duration;
using namespace ranges;
namespace boost
{
namespace gregorian
{
date &operator++(date &d)
{
return d = d + day(1);
}
date operator++(date &d, int)
{
return ++d - day(1);
}
}
}
namespace ranges
{
template<>
struct incrementable_traits<date>
{
using difference_type = date::duration_type::duration_rep::int_type;
};
}
CPP_assert(incrementable<date>);
auto
dates(unsigned short start, unsigned short stop)
{
return views::iota(date{start, greg::Jan, 1}, date{stop, greg::Jan, 1});
}
auto
dates_from(unsigned short year)
{
return views::iota(date{year, greg::Jan, 1});
}
auto
by_month()
{
return views::chunk_by(
[](date a, date b) { return a.month() == b.month(); });
}
auto
by_week()
{
return views::chunk_by([](date a, date b) {
// ++a because week_number is Mon-Sun and we want Sun-Sat
return (++a).week_number() == (++b).week_number();
});
}
std::string
format_day(date d)
{
return boost::str(boost::format("%|3|") % d.day());
}
// In: range<range<date>>: month grouped by weeks.
// Out: range<std::string>: month with formatted weeks.
auto
format_weeks()
{
return views::transform([](/*range<date>*/ auto week) {
return boost::str(boost::format("%1%%2%%|22t|") %
std::string(front(week).day_of_week() * 3u, ' ') %
(week | views::transform(format_day) | actions::join));
});
}
// Return a formatted string with the title of the month
// corresponding to a date.
std::string
month_title(date d)
{
return boost::str(boost::format("%|=22|") % d.month().as_long_string());
}
// In: range<range<date>>: year of months of days
// Out: range<range<std::string>>: year of months of formatted wks
auto
layout_months()
{
return views::transform([](/*range<date>*/ auto month) {
auto week_count =
static_cast<std::ptrdiff_t>(distance(month | by_week()));
return views::concat(
views::single(month_title(front(month))),
month | by_week() | format_weeks(),
views::repeat_n(std::string(22, ' '), 6 - week_count));
});
}
// Flattens a range of ranges by iterating the inner
// ranges in round-robin fashion.
template<class Rngs>
class interleave_view : public view_facade<interleave_view<Rngs>>
{
friend range_access;
std::vector<range_value_t<Rngs>> rngs_;
struct cursor;
cursor begin_cursor()
{
return {0, &rngs_, views::transform(rngs_, ranges::begin) | to<std::vector>};
}
public:
interleave_view() = default;
explicit interleave_view(Rngs rngs)
: rngs_(std::move(rngs) | to<std::vector>)
{}
};
template<class Rngs>
struct interleave_view<Rngs>::cursor
{
std::size_t n_;
std::vector<range_value_t<Rngs>> *rngs_;
std::vector<iterator_t<range_value_t<Rngs>>> its_;
decltype(auto) read() const
{
return *its_[n_];
}
void next()
{
if(0 == ((++n_) %= its_.size()))
for_each(its_, [](auto &it) { ++it; });
}
bool equal(default_sentinel_t) const
{
if(n_ != 0)
return false;
auto ends = *rngs_ | views::transform(ranges::end);
return its_.end() != std::mismatch(
its_.begin(), its_.end(), ends.begin(), std::not_equal_to<>{}).first;
}
CPP_member
auto equal(cursor const& that) const -> CPP_ret(bool)(
requires forward_range<range_value_t<Rngs>>)
{
return n_ == that.n_ && its_ == that.its_;
}
};
// In: range<range<T>>
// Out: range<T>, flattened by walking the ranges
// round-robin fashion.
auto
interleave()
{
return make_view_closure([](auto &&rngs) {
using Rngs = decltype(rngs);
return interleave_view<views::all_t<Rngs>>(
views::all(std::forward<Rngs>(rngs)));
});
}
// In: range<range<T>>
// Out: range<range<T>>, transposing the rows and columns.
auto
transpose()
{
return make_view_closure([](auto &&rngs) {
using Rngs = decltype(rngs);
CPP_assert(forward_range<Rngs>);
return std::forward<Rngs>(rngs)
| interleave()
| views::chunk(static_cast<std::size_t>(distance(rngs)));
});
}
// In: range<range<range<string>>>
// Out: range<range<range<string>>>, transposing months.
auto
transpose_months()
{
return views::transform(
[](/*range<range<string>>*/ auto rng) { return rng | transpose(); });
}
// In: range<range<string>>
// Out: range<string>, joining the strings of the inner ranges
auto
join_months()
{
return views::transform(
[](/*range<string>*/ auto rng) { return actions::join(rng); });
}
// In: range<date>
// Out: range<string>, lines of formatted output
auto
format_calendar(std::size_t months_per_line)
{
return
// Group the dates by month:
by_month()
// Format the month into a range of strings:
| layout_months()
// Group the months that belong side-by-side:
| views::chunk(months_per_line)
// Transpose the rows and columns of the size-by-side months:
| transpose_months()
// Ungroup the side-by-side months:
| views::join
// Join the strings of the transposed months:
| join_months();
}
int
main(int argc, char *argv[]) try
{
// Declare the supported options.
po::options_description desc("Allowed options");
desc.add_options()("help", "produce help message")(
"start", po::value<unsigned short>(), "Year to start")(
"stop", po::value<std::string>(), "Year to stop")(
"per-line",
po::value<std::size_t>()->default_value(3u),
"Nbr of months per line");
po::positional_options_description p;
p.add("start", 1).add("stop", 1);
po::variables_map vm;
po::store(
po::command_line_parser(argc, argv).options(desc).positional(p).run(),
vm);
po::notify(vm);
if(vm.count("help") || 1 != vm.count("start"))
{
std::cerr << desc << '\n';
return 1;
}
auto const start = vm["start"].as<unsigned short>();
auto const stop = 0 == vm.count("stop")
? (unsigned short)(start + 1)
: vm["stop"].as<std::string>() == "never"
? (unsigned short)-1
: boost::lexical_cast<unsigned short>(
vm["stop"].as<std::string>());
auto const months_per_line = vm["per-line"].as<std::size_t>();
if(stop != (unsigned short)-1 && stop <= start)
{
std::cerr << "ERROR: The stop year must be larger than the start"
<< '\n';
return 1;
}
if((unsigned short)-1 != stop)
{
copy(dates(start, stop) | format_calendar(months_per_line),
ostream_iterator<>(std::cout, "\n"));
}
else
{
copy(dates_from(start) | format_calendar(months_per_line),
ostream_iterator<>(std::cout, "\n"));
}
}
catch(std::exception &e)
{
std::cerr << "ERROR: Unhandled exception\n";
std::cerr << " what(): " << e.what();
return 1;
}
///[calendar]
#else
#pragma message( \
"calendar requires C++14 return type deduction and generic lambdas")
int
main()
{}
#endif
|
0 | repos/range-v3 | repos/range-v3/example/count.cpp | // Range v3 library
//
// Copyright Jeff Garland 2017
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
///[count]
// This example demonstrates counting the number of
// elements that match a given value.
// output...
// vector: 2
// array: 2
#include <iostream>
#include <range/v3/algorithm/count.hpp> // specific includes
#include <vector>
using std::cout;
int
main()
{
std::vector<int> v{6, 2, 3, 4, 5, 6};
// note the count return is a numeric type
// like int or long -- auto below make sure
// it matches the implementation
auto c = ranges::count(v, 6);
cout << "vector: " << c << '\n';
std::array<int, 6> a{6, 2, 3, 4, 5, 6};
c = ranges::count(a, 6);
cout << "array: " << c << '\n';
}
///[count]
|
0 | repos/range-v3 | repos/range-v3/example/comprehensions.cpp | // Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#include <chrono>
#include <iostream>
#include <range/v3/all.hpp>
using namespace ranges;
int
main()
{
// Define an infinite range containing all the Pythagorean triples:
auto triples = views::for_each(views::iota(1), [](int z) {
return views::for_each(views::iota(1, z + 1), [=](int x) {
return views::for_each(views::iota(x, z + 1), [=](int y) {
return yield_if(x * x + y * y == z * z,
std::make_tuple(x, y, z));
});
});
});
//// This alternate syntax also works:
// auto triples = iota(1) >>= [] (int z) { return
// iota(1, z+1) >>= [=](int x) { return
// iota(x, z+1) >>= [=](int y) { return
// yield_if(x*x + y*y == z*z,
// std::make_tuple(x, y, z)); };}; };
// Display the first 100 triples
RANGES_FOR(auto triple, triples | views::take(100))
{
std::cout << '(' << std::get<0>(triple) << ',' << std::get<1>(triple)
<< ',' << std::get<2>(triple) << ')' << '\n';
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////
// Benchmark Code
////////////////////////////////////////////////////////////////////////////////////////////////////
class timer
{
private:
std::chrono::high_resolution_clock::time_point start_;
public:
timer()
{
reset();
}
void reset()
{
start_ = std::chrono::high_resolution_clock::now();
}
std::chrono::milliseconds elapsed() const
{
return std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::high_resolution_clock::now() - start_);
}
friend std::ostream &operator<<(std::ostream &sout, timer const &t)
{
return sout << t.elapsed().count() << "ms";
}
};
void
benchmark()
{
// Define an infinite range containing all the Pythagorean triples:
auto triples = views::for_each(views::iota(1), [](int z) {
return views::for_each(views::iota(1, z + 1), [=](int x) {
return views::for_each(views::iota(x, z + 1), [=](int y) {
return yield_if(x * x + y * y == z * z,
std::make_tuple(x, y, z));
});
});
});
static constexpr int max_triples = 3000;
timer t;
int result = 0;
RANGES_FOR(auto triple, triples | views::take(max_triples))
{
int i, j, k;
std::tie(i, j, k) = triple;
result += (i + j + k);
}
std::cout << t << '\n';
std::cout << result << '\n';
result = 0;
int found = 0;
t.reset();
for(int z = 1;; ++z)
{
for(int x = 1; x <= z; ++x)
{
for(int y = x; y <= z; ++y)
{
if(x * x + y * y == z * z)
{
result += (x + y + z);
++found;
if(found == max_triples)
goto done;
}
}
}
}
done:
std::cout << t << '\n';
std::cout << result << '\n';
}
|
0 | repos/range-v3 | repos/range-v3/example/for_each_assoc.cpp |
// Range v3 library
//
// Copyright Jeff Garland 2017
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
///[for_each_assoc]
// for_each with associative containers
// output
// set: 1 2 3 4 5 6
// map: one:1 three:3 two:2
// unordered_map: three:3 one:1 two:2
// unordered_set: 6 5 4 3 2 1
#include <iostream>
#include <map>
#include <range/v3/algorithm/for_each.hpp>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
using std::cout;
using std::string;
auto print = [](int i) { cout << i << ' '; };
// must take a pair for map types
auto printm = [](std::pair<string, int> p) {
cout << p.first << ":" << p.second << ' ';
};
int
main()
{
cout << "set: ";
std::set<int> si{1, 2, 3, 4, 5, 6};
ranges::for_each(si, print);
cout << "\nmap: ";
std::map<string, int> msi{{"one", 1}, {"two", 2}, {"three", 3}};
ranges::for_each(msi, printm);
cout << "\nunordered map: ";
std::unordered_map<string, int> umsi{{"one", 1}, {"two", 2}, {"three", 3}};
ranges::for_each(umsi, printm);
cout << "\nunordered set: ";
std::unordered_set<int> usi{1, 2, 3, 4, 5, 6};
ranges::for_each(usi, print);
cout << '\n';
}
///[for_each_assoc]
|
0 | repos/range-v3 | repos/range-v3/example/any_all_none_of.cpp | // Range v3 library
//
// Copyright Jeff Garland 2017
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
//[any_all_none_of]]
// Demonstrates any_of, all_of, none_of
// output
// vector: [6,2,3,4,5,6]
// vector any_of is_six: true
// vector all_of is_six: false
// vector none_of is_six: false
#include <range/v3/algorithm/all_of.hpp>
#include <range/v3/algorithm/any_of.hpp>
#include <range/v3/algorithm/for_each.hpp>
#include <range/v3/algorithm/none_of.hpp>
#include <range/v3/view/all.hpp>
#include <iostream>
#include <vector>
using std::cout;
auto is_six = [](int i) { return i == 6; };
int
main()
{
std::vector<int> v{6, 2, 3, 4, 5, 6};
cout << std::boolalpha;
cout << "vector: " << ranges::views::all(v) << '\n';
cout << "vector any_of is_six: " << ranges::any_of(v, is_six) << '\n';
cout << "vector all_of is_six: " << ranges::all_of(v, is_six) << '\n';
cout << "vector none_of is_six: " << ranges::none_of(v, is_six) << '\n';
}
//[any_all_none_of]]
|
0 | repos/range-v3 | repos/range-v3/example/filter_transform.cpp | // Range v3 library
//
// Copyright Eric Niebler 2019
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
///[filter_transform]
// This example demonstrates filtering and transforming a range on the
// fly with view adaptors.
#include <iostream>
#include <string>
#include <vector>
#include <range/v3/view/filter.hpp>
#include <range/v3/view/transform.hpp>
using std::cout;
int main()
{
std::vector<int> const vi{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
using namespace ranges;
auto rng = vi | views::filter([](int i) { return i % 2 == 0; }) |
views::transform([](int i) { return std::to_string(i); });
// prints: [2,4,6,8,10]
cout << rng << '\n';
}
///[filter_transform]
|
0 | repos/range-v3 | repos/range-v3/example/CMakeLists.txt | set(CMAKE_FOLDER "example")
add_subdirectory(view)
# examples use a less draconian set of compiler warnings
ranges_append_flag(RANGES_HAS_WNO_MISSING_BRACES -Wno-missing-braces)
ranges_append_flag(RANGES_HAS_WNO_SHORTEN_64_TO_32 -Wno-shorten-64-to-32)
ranges_append_flag(RANGES_HAS_WNO_GLOBAL_CONSTRUCTORS -Wno-global-constructors)
rv3_add_test(example.comprehensions comprehensions comprehensions.cpp)
rv3_add_test(example.hello hello hello.cpp)
rv3_add_test(example.count count count.cpp)
rv3_add_test(example.count_if count_if count_if.cpp)
rv3_add_test(example.any_all_none_of any_all_none_of any_all_none_of.cpp)
rv3_add_test(example.for_each_sequence for_each_sequence for_each_sequence.cpp)
rv3_add_test(example.for_each_assoc for_each_assoc for_each_assoc.cpp)
rv3_add_test(example.is_sorted is_sorted is_sorted.cpp)
rv3_add_test(example.find find find.cpp)
rv3_add_test(example.filter_transform filter_transform filter_transform.cpp)
rv3_add_test(example.accumulate_ints accumulate_ints accumulate_ints.cpp)
rv3_add_test(example.comprehension_conversion comprehension_conversion comprehension_conversion.cpp)
rv3_add_test(example.sort_unique sort_unique sort_unique.cpp)
# Guarded with a variable because the calendar example causes gcc to puke.
if(RANGES_BUILD_CALENDAR_EXAMPLE)
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.59.0 COMPONENTS date_time program_options)
if (Boost_FOUND)
add_executable(range.v3.calendar calendar.cpp)
target_include_directories(range.v3.calendar SYSTEM PRIVATE ${Boost_INCLUDE_DIRS})
target_link_libraries(range.v3.calendar PRIVATE range-v3 Boost::date_time Boost::program_options)
message(STATUS "boost: ${Boost_LIBRARY_DIRS}")
target_compile_definitions(range.v3.calendar PRIVATE BOOST_NO_AUTO_PTR)
target_compile_options(range.v3.calendar PRIVATE -std=gnu++14)
endif()
endif()
|
0 | repos/range-v3 | repos/range-v3/example/find.cpp | // Range v3 library
//
// Copyright Jeff Garland 2017
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
///[find]
// vector: *i: 6
// didn't find 10
// *i: 6
// *i: 2
// *i after ++ (2 expected): 2
// array: *i: 6
// list: *i: 6
// fwd_list: *i: 4
// deque: *i: 6
#include <array>
#include <deque>
#include <forward_list>
#include <iostream>
#include <list>
#include <range/v3/all.hpp>
#include <vector>
using std::cout;
auto is_six = [](int i) -> bool { return i == 6; };
int
main()
{
cout << "vector: ";
std::vector<int> v{6, 2, 6, 4, 6, 1};
{
auto i = ranges::find(v, 6); // 1 2 3 4 5 6
cout << "*i: " << *i << '\n';
}
{
auto i = ranges::find(v, 10); // 1 2 3 4 5 6
if(i == ranges::end(v))
{
cout << "didn't find 10\n";
}
}
{
auto i = ranges::find_if(v, is_six);
if(i != ranges::end(v))
{
cout << "*i: " << *i << '\n';
}
}
{
auto i = ranges::find_if_not(v, is_six);
if(i != ranges::end(v))
{
cout << "*i: " << *i << '\n';
}
}
{
auto i = ranges::find(v, 6);
i++;
if(i != ranges::end(v))
{
cout << "*i after ++ (2 expected): " << *i;
}
}
cout << "\narray: ";
std::array<int, 6> a{6, 2, 3, 4, 5, 1};
{
auto i = ranges::find(a, 6);
if(i != ranges::end(a))
{
cout << "*i: " << *i;
}
}
cout << "\nlist: ";
std::list<int> li{6, 2, 3, 4, 5, 1};
{
auto i = ranges::find(li, 6);
if(i != ranges::end(li))
{
cout << "*i: " << *i;
}
}
cout << "\nfwd_list: ";
std::forward_list<int> fl{6, 2, 3, 4, 5, 1};
{
auto i = ranges::find(fl, 4);
if(i != ranges::end(fl))
{
cout << "*i: " << *i;
}
}
cout << "\ndeque: ";
std::deque<int> d{6, 2, 3, 4, 5, 1};
{
auto i = ranges::find(d, 6);
if(i != ranges::end(d))
{
cout << "*i: " << *i;
}
}
cout << '\n';
}
///[find]
|
0 | repos/range-v3 | repos/range-v3/example/hello.cpp |
// Range v3 library
//
// Copyright Jeff Garland 2017
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
///[hello]
#include <iostream>
#include <range/v3/all.hpp> // get everything
#include <string>
using std::cout;
int
main()
{
std::string s{"hello"};
// output: h e l l o
ranges::for_each(s, [](char c) { cout << c << ' '; });
cout << '\n';
}
///[hello]
|
0 | repos/range-v3 | repos/range-v3/example/comprehension_conversion.cpp | // Range v3 library
//
// Copyright Eric Niebler 2019
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
///[comprehension_conversion]
// Use a range comprehension (views::for_each) to construct a custom range, and
// then convert it to a std::vector.
#include <iostream>
#include <vector>
#include <range/v3/range/conversion.hpp>
#include <range/v3/view/for_each.hpp>
#include <range/v3/view/iota.hpp>
#include <range/v3/view/repeat_n.hpp>
using std::cout;
int main()
{
using namespace ranges;
auto vi = views::for_each(views::ints(1, 6),
[](int i) { return yield_from(views::repeat_n(i, i)); }) |
to<std::vector>();
// prints: [1,2,2,3,3,3,4,4,4,4,5,5,5,5,5]
cout << views::all(vi) << '\n';
}
///[comprehension_conversion]
|
0 | repos/range-v3 | repos/range-v3/example/count_if.cpp |
// Range v3 library
//
// Copyright Jeff Garland 2017
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
///[count_if]
// This example counts element of a range that match a supplied predicate.
// output
// vector: 2
// array: 2
#include <array>
#include <iostream>
#include <range/v3/algorithm/count_if.hpp> // specific includes
#include <vector>
using std::cout;
auto is_six = [](int i) -> bool { return i == 6; };
int
main()
{
std::vector<int> v{6, 2, 3, 4, 5, 6};
auto c = ranges::count_if(v, is_six);
cout << "vector: " << c << '\n'; // 2
std::array<int, 6> a{6, 2, 3, 4, 5, 6};
c = ranges::count_if(a, is_six);
cout << "array: " << c << '\n'; // 2
}
///[count_if]
|
0 | repos/range-v3 | repos/range-v3/example/accumulate_ints.cpp | // Range v3 library
//
// Copyright Eric Niebler 2019
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
///[accumulate_ints]
// Sums the first ten squares and prints them, using views::ints to generate
// and infinite range of integers, views::transform to square them, views::take
// to drop all but the first 10, and accumulate to sum them.
#include <iostream>
#include <vector>
#include <range/v3/numeric/accumulate.hpp>
#include <range/v3/view/iota.hpp>
#include <range/v3/view/take.hpp>
#include <range/v3/view/transform.hpp>
using std::cout;
int main()
{
using namespace ranges;
int sum = accumulate(views::ints(1, unreachable) | views::transform([](int i) {
return i * i;
}) | views::take(10),
0);
// prints: 385
cout << sum << '\n';
}
///[accumulate_ints]
|
0 | repos/range-v3 | repos/range-v3/example/is_sorted.cpp | // Range v3 library
//
// Copyright Jeff Garland 2017
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
///[is_sorted]
// Check if a container is sorted
// output
// vector: true
// array: false
#include <array>
#include <iostream>
#include <range/v3/algorithm/is_sorted.hpp> // specific includes
#include <vector>
using std::cout;
int
main()
{
cout << std::boolalpha;
std::vector<int> v{1, 2, 3, 4, 5, 6};
cout << "vector: " << ranges::is_sorted(v) << '\n';
std::array<int, 6> a{6, 2, 3, 4, 5, 6};
cout << "array: " << ranges::is_sorted(a) << '\n';
}
///[is_sorted]
|
0 | repos/range-v3 | repos/range-v3/example/sort_unique.cpp | // Range v3 library
//
// Copyright Eric Niebler 2019
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
///[sort_unique]
// Remove all non-unique elements from a container.
#include <iostream>
#include <vector>
#include <range/v3/action/sort.hpp>
#include <range/v3/action/unique.hpp>
#include <range/v3/view/all.hpp>
using std::cout;
int main()
{
std::vector<int> vi{9, 4, 5, 2, 9, 1, 0, 2, 6, 7, 4, 5, 6, 5, 9, 2, 7,
1, 4, 5, 3, 8, 5, 0, 2, 9, 3, 7, 5, 7, 5, 5, 6, 1,
4, 3, 1, 8, 4, 0, 7, 8, 8, 2, 6, 5, 3, 4, 5};
using namespace ranges;
vi |= actions::sort | actions::unique;
// prints: [0,1,2,3,4,5,6,7,8,9]
cout << views::all(vi) << '\n';
}
///[sort_unique]
|
0 | repos/range-v3/example | repos/range-v3/example/view/transform_golden.txt | [0.5,1,1.5]
|
0 | repos/range-v3/example | repos/range-v3/example/view/transform.cpp | //! [transform example]
#include <iostream>
#include <vector>
#include <range/v3/view/transform.hpp>
int main()
{
std::vector<int> numbers{1, 2, 3};
auto halved = numbers
// Divide each integer by 2, converting it into a double
| ranges::views::transform([](const int& num) {
return num / 2.0;
});
std::cout << halved << '\n';
}
//! [transform example]
|
0 | repos/range-v3/example | repos/range-v3/example/view/CMakeLists.txt | set(CMAKE_FOLDER "${CMAKE_FOLDER}/view")
rv3_add_test(example.view.transform example.view.transform transform.cpp)
rv3_add_test(example.view.ints example.view.ints ints.cpp)
rv3_add_test(example.view.filter example.view.filter filter.cpp)
# NOTE: Make sure the output matches the contents of the corresponding golden file
set_tests_properties(range.v3.example.view.transform PROPERTIES PASS_REGULAR_EXPRESSION "\\[0.5,1,1.5\\]")
set_tests_properties(range.v3.example.view.ints PROPERTIES PASS_REGULAR_EXPRESSION "\\[3,4,5,6\\]")
set_tests_properties(range.v3.example.view.filter PROPERTIES PASS_REGULAR_EXPRESSION "\\[2,4\\]")
|
0 | repos/range-v3/example | repos/range-v3/example/view/ints_golden.txt | [3,4,5,6]
|
0 | repos/range-v3/example | repos/range-v3/example/view/ints.cpp | //! [ints example]
#include <iostream>
#include <vector>
#include <range/v3/view/iota.hpp>
int main()
{
auto numbers = ranges::views::ints(3, 7);
std::cout << numbers << '\n';
}
//! [ints example]
|
0 | repos/range-v3/example | repos/range-v3/example/view/filter_golden.txt | [2,4]
|
0 | repos/range-v3/example | repos/range-v3/example/view/filter.cpp | //! [filter example]
#include <iostream>
#include <vector>
#include <range/v3/view/filter.hpp>
int main()
{
std::vector<int> numbers{1, 2, 3, 4};
auto even = numbers
// Keep only the even numbers
| ranges::views::filter([](const int& num) {
return num % 2 == 0;
});
std::cout << even << '\n';
}
//! [filter example]
|
0 | repos/range-v3 | repos/range-v3/perf/range_conversion.cpp | // Range v3 library
//
// Copyright 2019-present Christopher Di Bella
// Copyright 2019-present Eric Niebler
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Benchmark for https://github.com/ericniebler/range-v3/issues/1337
#include <string>
#include <vector>
#include <benchmark/benchmark.h>
#include <range/v3/algorithm/equal.hpp>
#include <range/v3/range/conversion.hpp>
#include <range/v3/range/primitives.hpp>
#include <range/v3/view/common.hpp>
#include <range/v3/view/reverse.hpp>
#include <range/v3/view/transform.hpp>
using namespace ranges;
namespace
{
auto palindrome_range_common(std::vector<std::string> const & words)
{
auto is_palindrome = [](auto const & word) {
return !ranges::empty(word) && ranges::equal(word, word | views::reverse);
};
auto palindrome_excalim = [&is_palindrome](auto const & word) {
return is_palindrome(word) ? word + '!' : word;
};
auto result = words | views::transform(palindrome_excalim) | views::common;
return std::vector<std::string>{ranges::begin(result), ranges::end(result)};
}
auto palindrome_range_to(std::vector<std::string> const & words)
{
auto is_palindrome = [](auto const & word) {
return !ranges::empty(word) && ranges::equal(word, word | views::reverse);
};
auto palindrome_excalim = [&is_palindrome](auto const & word) {
return is_palindrome(word) ? word + '!' : word;
};
return words | views::transform(palindrome_excalim) | ranges::to<std::vector>;
}
} // namespace
class Words : public ::benchmark::Fixture
{
protected:
std::vector<std::string> words_;
public:
void SetUp(const ::benchmark::State &)
{
auto magic = 476'000u;
words_.reserve(magic);
for(auto i = 0u; i < magic; ++i)
{
words_.push_back("this");
words_.push_back("is");
words_.push_back("his");
words_.push_back("face");
words_.push_back("abba");
words_.push_back("toot");
}
}
};
BENCHMARK_F(Words, RangeCommon)(benchmark::State & st)
{
for(auto _ : st)
{
auto result = ::palindrome_range_common(words_);
benchmark::DoNotOptimize(result.data());
benchmark::ClobberMemory();
}
}
BENCHMARK_F(Words, RangeTo)(benchmark::State & st)
{
for(auto _ : st)
{
auto result = ::palindrome_range_to(words_);
benchmark::DoNotOptimize(result.data());
benchmark::ClobberMemory();
}
}
|
0 | repos/range-v3 | repos/range-v3/perf/sort_patterns.cpp | // Range v3 library
//
// Copyright Eric Niebler 2013-present
// Copyright Gonzalo Brito Gadeschi 2015
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#include <range/v3/detail/config.hpp>
#if RANGES_CXX_RETURN_TYPE_DEDUCTION >= RANGES_CXX_RETURN_TYPE_DEDUCTION_14 && \
RANGES_CXX_GENERIC_LAMBDAS >= RANGES_CXX_GENERIC_LAMBDAS_14
#include <iostream>
#include <iomanip>
#include <vector>
#include <random>
#include <functional>
#include <climits>
#include <chrono>
#include <algorithm>
#include <range/v3/all.hpp>
RANGES_DIAGNOSTIC_IGNORE_GLOBAL_CONSTRUCTORS
RANGES_DIAGNOSTIC_IGNORE_SIGN_CONVERSION
namespace
{
/// Creates an geometric infinite sequence starting at 1 where the
/// successor is multiplied by \p V
auto geometric_sequence(std::size_t V) {
std::size_t N = 1;
return ranges::views::generate([N, V]() mutable {
auto old = N;
N *= V;
return old;
});
}
/// Creates an geometric infinite sequence starting at 1 where the
/// successor is multiplied by \p V
auto geometric_sequence_n(std::size_t V, std::size_t limit) {
return geometric_sequence(V) |
ranges::views::take_while([limit](std::size_t n) { return n <= limit; });
}
/// Random uniform integer sequence
struct random_uniform_integer_sequence {
std::default_random_engine gen;
std::uniform_int_distribution<> dist;
auto operator()(std::size_t) {
return ranges::views::generate([&]{ return dist(gen); });
}
static std::string name() { return "random_uniform_integer_sequence"; }
};
struct ascending_integer_sequence {
auto operator()(std::size_t) { return ranges::views::iota(1); }
static std::string name() { return "ascending_integer_sequence"; }
};
struct descending_integer_sequence {
auto operator()(std::size_t) {
return ranges::views::iota(0ll, std::numeric_limits<long long>::max()) |
ranges::views::reverse;
}
static std::string name() { return "descending_integer_sequence"; }
};
auto even = [](auto i) { return i % 2 == 0; };
auto odd = [](auto i) { return !even(i); };
struct even_odd_integer_sequence {
static std::string name() { return "even_odd_integer_sequence"; }
auto operator()(std::size_t n) {
return ranges::views::concat(ranges::views::ints(std::size_t{0}, n) | ranges::views::filter(even),
ranges::views::ints(std::size_t{0}, n) | ranges::views::filter(odd));
}
};
struct organ_pipe_integer_sequence {
static std::string name() { return "organ_pipe_integer_sequence"; }
auto operator()(std::size_t n) {
return ranges::views::concat(ranges::views::ints(std::size_t{0}, n/2),
ranges::views::ints(std::size_t{0}, n/2 + 1)
| ranges::views::reverse);
}
};
template<typename Seq>
void print(Seq seq, std::size_t n) {
std::cout << "sequence: " << seq.name() << '\n';
RANGES_FOR(auto i, seq(n) | ranges::views::take(n)) {
std::cout << i << '\n';
}
}
/// Returns the duration of a computation
using clock_t = std::chrono::high_resolution_clock;
using duration_t = clock_t::duration;
template<typename Computation>
auto duration(Computation &&c) {
auto time = []{ return clock_t::now(); };
const auto start = time();
c();
return time() - start;
}
template<typename Duration>
auto to_millis(Duration d) {
return std::chrono::duration_cast<std::chrono::milliseconds>(d).count();
}
template<typename Durations> auto compute_mean(Durations &&durations) {
using D = ranges::range_value_t<Durations>;
D total = ranges::accumulate(durations, D{}, ranges::plus{}, ranges::convert_to<D>{});
return total / ranges::size(durations);
}
template<typename Durations> auto compute_stddev(Durations &&durations) {
using D = ranges::range_value_t<Durations>;
using Rep = typename D::rep;
const auto mean = compute_mean(durations);
const auto stddev = ranges::accumulate(
durations | ranges::views::transform([=](auto i) {
auto const delta = (i - mean).count();
return delta * delta;
}), Rep{}, ranges::plus{}, ranges::convert_to<Rep>{});
return D{static_cast<typename D::rep>(std::sqrt(stddev / ranges::size(durations)))};
}
struct benchmark {
struct result_t {
duration_t mean_t;
duration_t max_t;
duration_t min_t;
std::size_t size;
duration_t deviation;
};
std::vector<result_t> results;
template<typename Computation, typename Sizes>
benchmark(Computation &&c, Sizes &&sizes, double target_deviation = 0.25,
std::size_t max_iters = 100, std::size_t min_iters = 5) {
RANGES_FOR(auto size, sizes) {
std::vector<duration_t> durations;
duration_t deviation;
duration_t mean_duration;
std::size_t iter;
for (iter = 0; iter < max_iters; ++iter) {
c.init(size);
durations.emplace_back(duration(c));
mean_duration = compute_mean(durations);
if (++iter == max_iters) {
break;
}
if (iter >= min_iters) {
deviation = compute_stddev(durations);
if (deviation < target_deviation * mean_duration)
break;
}
}
auto minmax = ranges::minmax(durations);
results.emplace_back(
result_t{mean_duration, minmax.max, minmax.min, size, deviation});
std::cerr << "size: " << size << " iter: " << iter
<< " dev: " << to_millis(deviation)
<< " mean: " << to_millis(mean_duration)
<< " max: " << to_millis(minmax.max)
<< " min: " << to_millis(minmax.min) << '\n';
}
}
};
template<typename Seq, typename Comp>
struct computation_on_sequence {
Seq seq;
Comp comp;
std::vector<ranges::range_value_t<decltype(seq(std::size_t{}))>> data;
computation_on_sequence(Seq s, Comp c, std::size_t max_size)
: seq(std::move(s)), comp(std::move(c)) {
data.reserve(max_size);
}
void init(std::size_t size) {
data.resize(size);
ranges::copy(seq(size) | ranges::views::take(size), ranges::begin(data));
}
void operator()() { comp(data); }
};
template<typename Seq, typename Comp>
auto make_computation_on_sequence(Seq s, Comp c, std::size_t max_size) {
return computation_on_sequence<Seq, Comp>(std::move(s), std::move(c),
max_size);
}
template<typename Seq> void benchmark_sort(Seq &&seq, std::size_t max_size) {
auto ranges_sort_comp =
make_computation_on_sequence(seq, ranges::sort, max_size);
auto std_sort_comp = make_computation_on_sequence(
seq, [](auto &&v) { std::sort(std::begin(v), std::end(v)); }, max_size);
auto ranges_sort_benchmark =
benchmark(ranges_sort_comp, geometric_sequence_n(2, max_size));
auto std_sort_benchmark =
benchmark(std_sort_comp, geometric_sequence_n(2, max_size));
using std::setw;
std::cout << '#'
<< "pattern: " << seq.name() << '\n';
std::cout << '#' << setw(19) << 'N' << setw(20) << "ranges::sort" << setw(20)
<< "std::sort"
<< '\n';
RANGES_FOR(auto p, ranges::views::zip(ranges_sort_benchmark.results,
std_sort_benchmark.results)) {
auto rs = p.first;
auto ss = p.second;
std::cout << setw(20) << rs.size << setw(20) << to_millis(rs.mean_t)
<< setw(20) << to_millis(ss.mean_t) << '\n';
}
}
} // unnamed namespace
int main()
{
constexpr std::size_t max_size = 2000000;
print(random_uniform_integer_sequence(), 20);
print(ascending_integer_sequence(), 20);
print(descending_integer_sequence(), 20);
print(even_odd_integer_sequence(), 20);
print(organ_pipe_integer_sequence(), 20);
benchmark_sort(random_uniform_integer_sequence(), max_size);
benchmark_sort(ascending_integer_sequence(), max_size);
benchmark_sort(descending_integer_sequence(), max_size);
benchmark_sort(organ_pipe_integer_sequence(), max_size);
}
#else
#pragma message("sort_patterns requires C++14 return type deduction and generic lambdas")
int main() {}
#endif
|
0 | repos/range-v3 | repos/range-v3/perf/counted_insertion_sort.cpp | // Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#include <chrono>
#include <iostream>
#include <random>
#include <range/v3/all.hpp>
RANGES_DIAGNOSTIC_IGNORE_SIGN_CONVERSION
class timer
{
public:
using clock_t = std::chrono::high_resolution_clock;
using duration_t = clock_t::time_point::duration;
timer()
{
reset();
}
void reset()
{
start_ = clock_t::now();
}
duration_t elapsed() const
{
return clock_t::now() - start_;
}
friend std::ostream &operator<<(std::ostream &sout, timer const &t)
{
return sout << t.elapsed().count() << "ms";
}
private:
clock_t::time_point start_;
};
template<typename D>
std::chrono::milliseconds::rep to_millis(D d) {
return std::chrono::duration_cast<std::chrono::milliseconds>(d).count();
}
template<typename It>
struct forward_iterator
{
It it_;
public:
typedef std::forward_iterator_tag iterator_category;
typedef typename std::iterator_traits<It>::value_type value_type;
typedef typename std::iterator_traits<It>::difference_type difference_type;
typedef It pointer;
typedef typename std::iterator_traits<It>::reference reference;
forward_iterator() = default;
explicit forward_iterator(It it) : it_(std::move(it)) {}
reference operator*() const {return *it_;}
pointer operator->() const {return it_;}
forward_iterator& operator++() {++it_; return *this;}
forward_iterator operator++(int)
{forward_iterator tmp(*this); ++(*this); return tmp;}
friend bool operator==(const forward_iterator& x, const forward_iterator& y)
{return x.it_ == y.it_;}
friend bool operator!=(const forward_iterator& x, const forward_iterator& y)
{return !(x == y);}
};
template<typename I, typename V2>
I upper_bound_n(I first, typename std::iterator_traits<I>::difference_type d, V2 const &val)
{
while(0 != d)
{
auto half = d / 2;
auto middle = std::next(first, half);
if(val < *middle)
d = half;
else
{
first = ++middle;
d -= half + 1;
}
}
return first;
}
template<typename I>
void insertion_sort_n(I first, typename std::iterator_traits<I>::difference_type n)
{
auto m = 0;
for(auto it = first; m != n; ++it, ++m)
{
auto insertion = upper_bound_n(first, m, *it);
ranges::rotate(insertion, it, std::next(it));
}
}
template<typename I, typename S>
void insertion_sort(I first, S last)
{
for(auto it = first; it != last; ++it)
{
auto insertion = ranges::upper_bound(first, it, *it);
ranges::rotate(insertion, it, std::next(it));
}
}
template<typename Rng>
void insertion_sort(Rng && rng)
{
::insertion_sort(std::begin(rng), std::end(rng));
}
std::unique_ptr<int> data(int i)
{
std::unique_ptr<int> a(new int[i]);
auto rng = ranges::views::counted(a.get(), i);
ranges::iota(rng, 0);
return a;
}
template<typename Gen>
void shuffle(int *a, int i, Gen && rand)
{
auto rng = ranges::views::counted(a, i);
rng |= ranges::actions::shuffle(std::forward<Gen>(rand));
}
constexpr int cloops = 3;
template<typename I>
void benchmark_n(int i)
{
std::mt19937 gen;
auto a = data(i);
timer::duration_t ms = {};
for(int j = 0; j < cloops; ++j)
{
::shuffle(a.get(), i, gen);
timer t;
insertion_sort_n(I{a.get()}, i);
ms += t.elapsed();
}
std::cout << to_millis(ms/cloops) << std::endl;
}
template<typename I>
void benchmark_counted(int i)
{
std::mt19937 gen;
auto a = data(i);
timer::duration_t ms = {};
for(int j = 0; j < cloops; ++j)
{
::shuffle(a.get(), i, gen);
timer t;
insertion_sort(ranges::views::counted(I{a.get()}, i));
ms += t.elapsed();
}
std::cout << to_millis(ms/cloops) << std::endl;
}
int main(int argc, char *argv[])
{
if(argc < 2)
return -1;
int i = std::atoi(argv[1]);
std::cout << "insertion_sort_n (random-access) : ";
benchmark_n<int*>(i);
std::cout << "insertion_sort (random-access) : ";
benchmark_counted<int*>(i);
std::cout << "\n";
std::cout << "insertion_sort_n (forward) : ";
benchmark_n<forward_iterator<int*>>(i);
std::cout << "insertion_sort (forward) : ";
benchmark_counted<forward_iterator<int*>>(i);
}
|
0 | repos/range-v3 | repos/range-v3/perf/CMakeLists.txt | set(CMAKE_FOLDER "perf")
add_executable(range_v3_counted_insertion_sort counted_insertion_sort.cpp)
target_link_libraries(range_v3_counted_insertion_sort range-v3::range-v3)
add_executable(range_v3_range_conversion range_conversion.cpp)
target_link_libraries(range_v3_range_conversion range-v3::range-v3 benchmark_main)
add_executable(range_v3_sort_patterns sort_patterns.cpp)
target_link_libraries(range_v3_sort_patterns range-v3::range-v3)
|
0 | repos/range-v3 | repos/range-v3/.vscode/tasks.json | {
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"options": {
"cwd": "${workspaceRoot}/../range-build"
},
"tasks": [
{
"label": "cmake",
"type": "shell",
"command": "cmake -G 'Unix Makefiles' -DCMAKE_BUILD_TYPE=Debug ../range-v3",
"group": "build",
"presentation": {
"reveal": "always",
"panel": "new"
}
},
{
"label": "make",
"type": "shell",
"command": "make -j8",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always",
"panel": "new"
}
}
]
}
|
0 | repos/range-v3 | repos/range-v3/.vscode/settings.json | {
"files.associations": {
"iterator": "cpp",
"*.ipp": "cpp",
"array": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"initializer_list": "cpp",
"string_view": "cpp",
"*.tcc": "cpp",
"atomic": "cpp",
"bit": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"map": "cpp",
"set": "cpp",
"exception": "cpp",
"fstream": "cpp",
"functional": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"mutex": "cpp",
"new": "cpp",
"numeric": "cpp",
"optional": "cpp",
"ostream": "cpp",
"ratio": "cpp",
"regex": "cpp",
"shared_mutex": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"system_error": "cpp",
"thread": "cpp",
"type_traits": "cpp",
"tuple": "cpp",
"typeinfo": "cpp",
"utility": "cpp",
"__config": "cpp",
"__bit_reference": "cpp",
"__debug": "cpp",
"__functional_base": "cpp",
"__locale": "cpp",
"__mutex_base": "cpp",
"__nullptr": "cpp",
"__threading_support": "cpp",
"__tuple": "cpp",
"coroutine": "cpp",
"ios": "cpp",
"locale": "cpp",
"random": "cpp",
"__node_handle": "cpp",
"__tree": "cpp",
"climits": "cpp",
"__memory": "cpp",
"strstream": "cpp",
"complex": "cpp",
"iomanip": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp",
"variant": "cpp",
"__split_buffer": "cpp",
"filesystem": "cpp",
"queue": "cpp",
"stack": "cpp",
"__errc": "cpp",
"__hash_table": "cpp",
"__string": "cpp",
"algorithm": "cpp",
"codecvt": "cpp",
"valarray": "cpp",
"version": "cpp",
"source_location": "cpp",
"span": "cpp",
"ranges": "cpp",
"compare": "cpp",
"concepts": "cpp",
"stop_token": "cpp",
"cfenv": "cpp",
"__bits": "cpp",
"numbers": "cpp",
"semaphore": "cpp"
},
"C_Cpp.configurationWarnings": "Disabled",
"cmake.configureOnOpen": true,
"C_Cpp.intelliSenseEngineFallback": "Enabled"
}
|
0 | repos/range-v3 | repos/range-v3/.vscode/c_cpp_properties.json | {
"configurations": [
{
"name": "Mac",
"includePath": [
"/Users/eniebler/llvm-install/include/c++/v1",
"/usr/local/include",
"/Users/eniebler/llvm-install/lib/clang/6.0.0/include",
"/usr/include",
"${workspaceRoot}/include",
"/usr/local/opt/[email protected]/incluse"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/Users/eniebler/llvm-install/include/c++/v1",
"/usr/local/include",
"/Users/eniebler/llvm-install/lib/clang/6.0.0/include",
"/usr/include",
"${workspaceRoot}/include",
"/usr/local/opt/[email protected]/incluse"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"macFrameworkPath": [
"/System/Library/Frameworks",
"/Library/Frameworks"
],
"compilerPath": "/Users/eniebler/llvm-install/bin/clang++",
"cStandard": "c11",
"cppStandard": "c++11",
"configurationProvider": "vector-of-bool.cmake-tools"
},
{
"name": "Linux",
"includePath": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}/include"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"/usr/include",
"/usr/local/include",
"${workspaceRoot}/include"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"cStandard": "c11",
"cppStandard": "c++11",
"configurationProvider": "ms-vscode.cmake-tools"
},
{
"name": "Win32",
"includePath": [
"${workspaceRoot}/include"
],
"defines": [
"_DEBUG",
"UNICODE"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${workspaceRoot}/include"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"cStandard": "c11",
"cppStandard": "c++11"
}
],
"version": 4
} |
0 | repos/range-v3 | repos/range-v3/test_package/example.cpp | // Range v3 library
//
// Copyright Eric Niebler 2013-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#include <range/v3/all.hpp>
#include <iostream>
using namespace ranges;
// A range that iterates over all the characters in a
// null-terminated string.
class c_string_range
: public view_facade<c_string_range>
{
friend range_access;
char const * sz_;
char const & read() const { return *sz_; }
bool equal(default_sentinel_t) const { return *sz_ == '\0'; }
void next() { ++sz_; }
public:
c_string_range() = default;
explicit c_string_range(char const *sz) : sz_(sz)
{
assert(sz != nullptr);
}
};
int main()
{
c_string_range r("hello world");
// Iterate over all the characters and print them out
ranges::for_each(r, [](char ch){
std::cout << ch << ' ';
});
// prints: h e l l o w o r l d
}
|
0 | repos/range-v3 | repos/range-v3/test_package/CMakeLists.txt | # Range v3 library
#
# Copyright Luis Martinez de Bartolome Izquierdo 2016
#
# Use, modification and distribution is subject to the
# Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
# Project home: https://github.com/ericniebler/range-v3
#
PROJECT(PackageTest)
cmake_minimum_required(VERSION 3.1.0 FATAL_ERROR)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_executable(range-v3-example example.cpp)
target_link_libraries(range-v3-example ${CONAN_LIBS})
set_property(TARGET range-v3-example PROPERTY CXX_STANDARD 17)
|
0 | repos/range-v3 | repos/range-v3/test_package/conanfile.py | # Range v3 library
#
# Copyright Luis Martinez de Bartolome Izquierdo 2016
#
# Use, modification and distribution is subject to the
# Boost Software License, Version 1.0. (See accompanying
# file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
#
# Project home: https://github.com/ericniebler/range-v3
#
from conans import ConanFile, CMake
import os
class Rangev3TestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def imports(self):
self.copy("*.dll", "bin", "bin")
self.copy("*.dylib", "bin", "bin")
def test(self):
os.chdir("bin")
self.run(".%srange-v3-example" % os.sep)
|
0 | repos/range-v3 | repos/range-v3/test/bug-guard.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <range/v3/iterator.hpp>
#include <range/v3/utility.hpp>
int main()
{
// make sure, that `utility.hpp` is included correctly
ranges::optional<int> a;
(void) a;
}
|
0 | repos/range-v3 | repos/range-v3/test/bug1633.cpp | // Range v3 library
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <cstddef>
#include <iterator>
#include <range/v3/iterator.hpp>
struct X { };
namespace std {
template<> struct iterator_traits<X> { };
}
struct Y {
using difference_type = std::ptrdiff_t;
using value_type = int;
using pointer = int*;
using reference = int&;
using iterator_category = std::forward_iterator_tag;
};
static_assert(ranges::detail::is_std_iterator_traits_specialized_v<X>, "");
static_assert(!ranges::detail::is_std_iterator_traits_specialized_v<Y>, "");
static_assert(!ranges::detail::is_std_iterator_traits_specialized_v<int*>, "");
int main()
{
}
|
0 | repos/range-v3 | repos/range-v3/test/constexpr_core.cpp | // Range v3 library
//
// Copyright Gonzalo Brito Gadeschi 2015
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <range/v3/detail/config.hpp>
#if RANGES_CXX_CONSTEXPR >= RANGES_CXX_CONSTEXPR_14
#include <range/v3/range/access.hpp>
#include <range/v3/range/operations.hpp>
#include <range/v3/range/primitives.hpp>
#include <range/v3/utility/addressof.hpp>
#include "array.hpp"
#include "test_iterators.hpp"
// Test sequence 1,2,3,4
template<typename It>
constexpr /*c++14*/ auto test_it_back(It, It last,
std::bidirectional_iterator_tag) -> bool
{
auto end_m1_2 = It{ranges::prev(last, 1)};
if (*end_m1_2 != 4) { return false; }
return true;
}
template<typename It, typename Concept>
constexpr /*c++14*/ auto test_it_back(It, It, Concept) -> bool
{
return true;
}
template<typename It>
constexpr /*c++14*/ auto test_it_(It beg, It last) -> bool
{
if (*beg != 1) { return false; }
if (ranges::distance(beg, last) != 4) { return false; }
if (ranges::next(beg, 4) != last) { return false; }
auto end_m1 = It{ranges::next(beg, 3)};
if (*end_m1 != 4) { return false; }
if (!test_it_back(beg, last, ranges::iterator_tag_of<It>{})) { return false; }
auto end2 = beg;
ranges::advance(end2, last);
if (end2 != last) { return false; }
auto end3 = beg;
ranges::advance(end3, 4);
if (end3 != last) { return false; }
if (ranges::iter_enumerate(beg, last) != std::pair<std::ptrdiff_t, It>{4, last})
{
return false;
}
if (ranges::iter_distance(beg, last) != 4) { return false; }
if (ranges::iter_distance_compare(beg, last, 4) != 0) { return false; }
if (ranges::iter_distance_compare(beg, last, 3) != 1) { return false; }
if (ranges::iter_distance_compare(beg, last, 5) != -1) { return false; }
return true;
}
// Test sequence 4,3,2,1 (for reverse iterators)
template<typename It>
constexpr /*c++14*/ auto test_rit_(It beg, It last) -> bool
{
if (ranges::distance(beg, last) != 4) { return false; }
if (ranges::next(beg, 4) != last) { return false; }
auto end_m1 = It{ranges::next(beg, 3)};
if (*end_m1 != 1) { return false; }
if (ranges::detail::is_convertible<ranges::iterator_tag_of<It>,
std::bidirectional_iterator_tag>{})
{
auto end_m1_2 = It{ranges::prev(last, 1)};
if (*end_m1_2 != 1) { return false; }
}
auto end2 = beg;
ranges::advance(end2, last);
if (end2 != last) { return false; }
auto end3 = beg;
ranges::advance(end3, 4);
if (end3 != last) { return false; }
using D = ranges::iter_difference_t<It>;
if (ranges::iter_enumerate(beg, last) != std::pair<D, It>{4, last})
{
return false;
}
if (ranges::iter_distance(beg, last) != 4) { return false; }
if (ranges::iter_distance_compare(beg, last, 4) != 0) { return false; }
if (ranges::iter_distance_compare(beg, last, 3) != 1) { return false; }
if (ranges::iter_distance_compare(beg, last, 5) != -1) { return false; }
return true;
}
template<typename It, typename Sequence1234>
constexpr /*c++14*/ auto test_it(Sequence1234&& a) -> bool
{
auto beg = It{ranges::begin(a)};
auto last = It{ranges::end(a)};
return test_it_(beg, last);
}
template<typename Sequence1234>
constexpr /*c++14*/ auto test_its_c(Sequence1234&& a) -> bool
{
return test_it<InputIterator<int const *>>(a)
&& test_it<ForwardIterator<int const *>>(a)
&& test_it<BidirectionalIterator<int const *>>(a)
&& test_it<RandomAccessIterator<int const *>>(a);
}
template<typename Sequence1234>
constexpr /*c++14*/ auto test_its(Sequence1234&& a) -> bool
{
return test_it<InputIterator<int *>>(a)
&& test_it<ForwardIterator<int *>>(a)
&& test_it<BidirectionalIterator<int *>>(a)
&& test_it<RandomAccessIterator<int *>>(a)
&& test_its_c(a);
}
template<typename It, typename Sequence1234>
constexpr /*c++14*/ auto test_rit(Sequence1234&& a) -> bool
{
auto beg = It{ranges::rbegin(a)};
auto last = It{ranges::rend(a)};
return test_rit_(beg, last);
}
template<typename Sequence1234>
constexpr /*c++14*/ auto test_rits(Sequence1234&& a) -> bool
{
using rit = decltype(ranges::rbegin(a));
return test_rit<BidirectionalIterator<rit>>(a)
&& test_rit<BidirectionalIterator<rit>>(a);
}
template<typename It, typename Sequence1234>
constexpr /*c++14*/ auto test_cit(Sequence1234&& a) -> bool
{
auto beg = It{ranges::cbegin(a)};
auto last = It{ranges::cend(a)};
return test_it_(beg, last);
}
template<typename Sequence1234>
constexpr /*c++14*/ auto test_cits(Sequence1234&& a) -> bool
{
return test_cit<InputIterator<int const *>>(a)
&& test_cit<ForwardIterator<int const *>>(a)
&& test_cit<BidirectionalIterator<int const *>>(a)
&& test_cit<RandomAccessIterator<int const *>>(a);
}
template<typename It, typename Sequence1234>
constexpr /*c++14*/ auto test_crit(Sequence1234&& a) -> bool
{
auto beg = It{ranges::crbegin(a)};
auto last = It{ranges::crend(a)};
return test_rit_(beg, last);
}
template<typename Sequence1234>
constexpr /*c++14*/ auto test_crits(Sequence1234&& a) -> bool
{
using rit = decltype(ranges::crbegin(a));
return test_crit<BidirectionalIterator<rit>>(a)
&& test_crit<RandomAccessIterator<rit>>(a);
}
template<typename Sequence1234>
constexpr /*c++14*/ auto test_non_member_f(Sequence1234&& a) -> bool
{
if (ranges::empty(a)) { return false; }
if (ranges::front(a) != 1) { return false; }
if (ranges::back(a) != 4) { return false; }
if (ranges::index(a, 2) != 3) { return false; }
if (ranges::at(a, 2) != 3) { return false; }
if (ranges::size(a) != 4) { return false; }
return true;
}
constexpr /*c++14*/ auto test_array() -> bool
{
test::array<int, 4> a{{1, 2, 3, 4}};
auto beg = ranges::begin(a);
auto three = ranges::next(beg, 2);
if ((false)) {
ranges::iter_swap(beg, three);
if (*beg != 3) { return false; }
if (*three != 1) { return false; }
ranges::iter_swap(beg, three);
}
if (!test_its(a)) { return false; }
if (!test_cits(a)) { return false; }
if (!test_rits(a)) { return false; }
if (!test_crits(a)) { return false; }
if (!test_non_member_f(a)) { return false; }
// This can be worked around but is just bad:
test::array<int, 4> b{{5, 6, 7, 8}};
ranges::swap(a, b);
if (a[0] != 5 || b[0] != 1 || a[3] != 8 || b[3] != 4) { return false; }
return true;
}
constexpr /*c++14*/ auto test_c_array() -> bool
{
int a[4]{1, 2, 3, 4};
if (!test_its(a)) { return false; }
if (!test_cits(a)) { return false; }
if (!test_rits(a)) { return false; }
if (!test_crits(a)) { return false; }
if (!test_non_member_f(a)) { return false; }
// C-arrays have no associated namespace, so this can't work:
// int b[4]{5, 6, 7, 8};
// ranges::swap(a, b);
// if (a[0] != 5 || b[0] != 1 || a[3] != 8 || b[3] != 4) { return false; }
return true;
}
constexpr /*c++14*/ auto test_init_list() -> bool
{
std::initializer_list<int> a{1, 2, 3, 4};
if (!test_its_c(a)) { return false; }
if (!test_cits(a)) { return false; }
if (!test_rits(a)) { return false; }
if (!test_crits(a)) { return false; }
if (!test_non_member_f(a)) { return false; }
std::initializer_list<int> b{5, 6, 7, 8};
ranges::swap(a, b);
if (ranges::at(a, 0) != 5 || ranges::at(b, 0) != 1
|| ranges::at(a, 3) != 8 || ranges::at(b, 3) != 4)
{
return false;
}
return true;
}
#ifdef __cpp_lib_addressof_constexpr
#define ADDR_CONSTEXPR constexpr
#else
#define ADDR_CONSTEXPR
#endif
namespace addr {
struct Good { };
struct Bad { void operator&() const; };
struct Bad2 { friend void operator&(Bad2); };
}
void test_constexpr_addressof() {
static constexpr int i = 0;
static constexpr int const* pi = ranges::detail::addressof(i);
static_assert(&i == pi, "");
static constexpr addr::Good g = {};
static constexpr addr::Good const* pg = ranges::detail::addressof(g);
static_assert(&g == pg, "");
static constexpr addr::Bad b = {};
static ADDR_CONSTEXPR addr::Bad const* pb = ranges::detail::addressof(b);
static constexpr addr::Bad2 b2 = {};
static ADDR_CONSTEXPR addr::Bad2 const* pb2 = ranges::detail::addressof(b2);
#ifdef __cpp_lib_addressof_constexpr
static_assert(std::addressof(b) == pb, "");
static_assert(std::addressof(b2) == pb2, "");
#else
(void)pb;
(void)pb2;
#endif
}
int main()
{
static_assert(test_array(), "");
static_assert(test_c_array(), "");
static_assert(test_init_list(), "");
}
#else
int main() {}
#endif
|
0 | repos/range-v3 | repos/range-v3/test/array.hpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// The implementation of array has been adapted from libc++
// (http://libcxx.llvm.org).
//
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef RANGES_V3_TEST_ARRAY_HPP
#define RANGES_V3_TEST_ARRAY_HPP
#include <stdexcept>
#include <range/v3/range_fwd.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/algorithm/fill_n.hpp>
#include <range/v3/algorithm/swap_ranges.hpp>
#include <range/v3/algorithm/equal.hpp>
#include <range/v3/algorithm/lexicographical_compare.hpp>
#include <range/v3/utility/swap.hpp>
namespace test {
/// \addtogroup group-utility
/// A std::array with constexpr support
template<typename T, std::size_t N>
struct array
{
using self = array;
using value_type = T;
using reference = value_type&;
using const_reference = value_type const&;
using iterator = value_type*;
using const_iterator = value_type const*;
using pointer = value_type*;
using const_pointer = value_type const*;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;
using reverse_iterator = ranges::reverse_iterator<iterator>;
using const_reverse_iterator = ranges::reverse_iterator<const_iterator>;
value_type elems_[N > 0 ? N : 1];
constexpr /*c++14*/ void fill(const value_type& u)
{
ranges::fill_n(elems_, N, u);
}
constexpr /*c++14*/
void swap(array& a) noexcept(ranges::is_nothrow_swappable<T>::value)
{
ranges::swap_ranges(elems_, elems_ + N, a.elems_);
}
// iterators:
constexpr /*c++14*/
iterator begin() noexcept
{
return iterator(elems_);
}
constexpr /*c++14*/
const_iterator begin() const noexcept
{
return const_iterator(elems_);
}
constexpr /*c++14*/
iterator end() noexcept
{
return iterator(elems_ + N);
}
constexpr /*c++14*/
const_iterator end() const noexcept
{
return const_iterator(elems_ + N);
}
constexpr /*c++14*/
reverse_iterator rbegin() noexcept
{
return reverse_iterator(end());
}
constexpr /*c++14*/
const_reverse_iterator rbegin() const noexcept
{
return const_reverse_iterator(end());
}
constexpr /*c++14*/
reverse_iterator rend() noexcept
{
return reverse_iterator(begin());
}
constexpr /*c++14*/
const_reverse_iterator rend() const noexcept
{
return const_reverse_iterator(begin());
}
constexpr /*c++14*/
const_iterator cbegin() const noexcept
{
return begin();
}
constexpr /*c++14*/
const_iterator cend() const noexcept
{
return end();
}
constexpr /*c++14*/
const_reverse_iterator crbegin() const noexcept
{
return rbegin();
}
constexpr /*c++14*/
const_reverse_iterator crend() const noexcept
{
return rend();
}
// capacity:
constexpr /*c++14*/
size_type size() const noexcept
{
return N;
}
constexpr /*c++14*/
size_type max_size() const noexcept
{
return N;
}
constexpr /*c++14*/
bool empty() const noexcept
{
return N == 0;
}
// element access:
constexpr /*c++14*/ reference operator[](size_type n)
{
return elems_[n];
}
constexpr /*c++14*/ const_reference operator[](size_type n) const
{
return elems_[n];
}
constexpr /*c++14*/ reference at(size_type n)
{
if (n >= N)
throw std::out_of_range("array::at");
return elems_[n];
}
constexpr /*c++14*/ const_reference at(size_type n) const
{
if (n >= N)
throw std::out_of_range("array::at");
return elems_[n];
}
constexpr /*c++14*/ reference front()
{
return elems_[0];
}
constexpr /*c++14*/ const_reference front() const
{
return elems_[0];
}
constexpr /*c++14*/ reference back()
{
return elems_[N > 0 ? N-1 : 0];
}
constexpr /*c++14*/ const_reference back() const
{
return elems_[N > 0 ? N-1 : 0];
}
constexpr /*c++14*/
value_type* data() noexcept
{
return elems_;
}
constexpr /*c++14*/
const value_type* data() const noexcept
{
return elems_;
}
};
template<class T, size_t N>
constexpr /*c++14*/
bool
operator==(const array<T, N>& x, const array<T, N>& y)
{
return ranges::equal(x.elems_, x.elems_ + N, y.elems_);
}
template<class T, size_t N>
constexpr /*c++14*/
bool
operator!=(const array<T, N>& x, const array<T, N>& y)
{
return !(x == y);
}
template<class T, size_t N>
constexpr /*c++14*/
bool
operator<(const array<T, N>& x, const array<T, N>& y)
{
return ranges::lexicographical_compare(x.elems_, x.elems_ + N, y.elems_, y.elems_ + N);
}
template<class T, size_t N>
constexpr /*c++14*/
bool
operator>(const array<T, N>& x, const array<T, N>& y)
{
return y < x;
}
template<class T, size_t N>
constexpr /*c++14*/
bool
operator<=(const array<T, N>& x, const array<T, N>& y)
{
return !(y < x);
}
template<class T, size_t N>
constexpr /*c++14*/
bool
operator>=(const array<T, N>& x, const array<T, N>& y)
{
return !(x < y);
}
template<class T, size_t N>
constexpr /*c++14*/
auto swap(array<T, N>& x, array<T, N>& y)
noexcept(ranges::is_nothrow_swappable<T>::value)
-> typename std::enable_if<ranges::is_swappable<T>::value, void>::type
{
x.swap(y);
}
template<size_t I, class T, size_t N>
constexpr /*c++14*/
T& get(array<T, N>& a) noexcept
{
static_assert(I < N, "Index out of bounds in ranges::get<> (ranges::array)");
return a.elems_[I];
}
template<size_t I, class T, size_t N>
constexpr /*c++14*/
const T& get(const array<T, N>& a) noexcept
{
static_assert(I < N, "Index out of bounds in ranges::get<> (const ranges::array)");
return a.elems_[I];
}
template<size_t I, class T, size_t N>
constexpr /*c++14*/
T && get(array<T, N>&& a) noexcept
{
static_assert(I < N, "Index out of bounds in ranges::get<> (ranges::array &&)");
return std::move(a.elems_[I]);
}
template<class T, std::size_t N>
constexpr /*c++14*/ void swap(array<T, N>& a, array<T, N>& b) {
for(std::size_t i = 0; i != N; ++i) {
auto tmp = std::move(a[i]);
a[i] = std::move(b[i]);
b[i] = std::move(tmp);
}
}
} // namespace test
RANGES_DIAGNOSTIC_PUSH
RANGES_DIAGNOSTIC_IGNORE_MISMATCHED_TAGS
namespace std
{
template<class T, size_t N>
class tuple_size<test::array<T, N>>
: public integral_constant<size_t, N> {};
template<size_t I, class T, size_t N>
class tuple_element<I, test::array<T, N> >
{
public:
using type = T;
};
} // namespace std
RANGES_DIAGNOSTIC_POP
#endif // RANGES_V3_TEST_ARRAY_HPP
|
0 | repos/range-v3 | repos/range-v3/test/CMakeLists.txt | include(../cmake/ranges_diagnostics.cmake)
set(CMAKE_FOLDER "test")
add_subdirectory(action)
add_subdirectory(algorithm)
add_subdirectory(iterator)
add_subdirectory(functional)
add_subdirectory(numeric)
add_subdirectory(range)
add_subdirectory(utility)
add_subdirectory(view)
add_subdirectory(experimental)
rv3_add_test(test.config config config.cpp)
rv3_add_test(test.constexpr_core constexpr_core constexpr_core.cpp)
rv3_add_test(test.multiple multiple multiple1.cpp multiple2.cpp)
rv3_add_test(test.bug474 bug474 bug474.cpp)
rv3_add_test(test.bug566 bug566 bug566.cpp)
rv3_add_test(test.bug1322 bug1322 bug1322.cpp)
rv3_add_test(test.bug1335 bug1335 bug1335.cpp)
rv3_add_test(test.bug1633 bug1633 bug1633.cpp)
rv3_add_test(test.bug1729 bug1729 bug1729.cpp)
rv3_add_test(test.bug-guard bug-guard bug-guard.cpp)
|
0 | repos/range-v3 | repos/range-v3/test/bug1729.cpp | #ifdef _MSC_VER
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#endif
#include <complex.h>
#include <range/v3/all.hpp>
int main() {
}
|
0 | repos/range-v3 | repos/range-v3/test/test_utils.hpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef RANGES_TEST_UTILS_HPP
#define RANGES_TEST_UTILS_HPP
#include <algorithm>
#include <cstring>
#include <functional>
#include <initializer_list>
#include <ostream>
#include <meta/meta.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/access.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/view/subrange.hpp>
#include "./debug_view.hpp"
#include "./simple_test.hpp"
#include "./test_iterators.hpp"
#if defined(__clang__) || defined(__GNUC__)
#if defined(__has_builtin)
#if __has_builtin(__builtin_FILE) && \
__has_builtin(__builtin_LINE) && \
__has_builtin(__builtin_FUNCTION)
#define RANGES_CXX_HAS_SLOC_BUILTINS
#endif
#endif
#else
#define RANGES_CXX_HAS_SLOC_BUILTINS
#endif
#if defined(RANGES_CXX_HAS_SLOC_BUILTINS) && defined(__has_include)
#if __has_include(<source_location>)
#include <source_location>
#ifdef __cpp_lib_source_location
#define RANGES_HAS_SLOC 1
using source_location = std::source_location;
#endif
#elif __has_include(<experimental/source_location>)
#include <experimental/source_location>
#if __cpp_lib_experimental_source_location
#define RANGES_HAS_SLOC 1
using source_location = std::experimental::source_location;
#endif
#endif
#endif
#ifndef RANGES_HAS_SLOC
struct source_location
{
static source_location current()
{
return {};
}
};
#define CHECK_SLOC(sloc, ...) \
do \
{ \
(void)sloc; \
CHECK(__VA_ARGS__); \
} while(false)
#else
#define CHECK_SLOC(sloc, ...) CHECK_LINE(sloc.file_name(), (int)sloc.line(), __VA_ARGS__)
#endif
RANGES_DIAGNOSTIC_PUSH
RANGES_DIAGNOSTIC_IGNORE_DEPRECATED_THIS_CAPTURE
template<typename T, typename U>
CPP_concept both_ranges = ranges::input_range<T> && ranges::input_range<U>;
struct check_equal_fn
{
CPP_template(typename T, typename U)(
requires(!both_ranges<T, U>)) //
constexpr void operator()(
T && actual, U && expected,
source_location sloc = source_location::current()) const
{
CHECK_SLOC(sloc, (T &&) actual == (U &&) expected);
}
CPP_template(typename Rng1, typename Rng2)(
requires both_ranges<Rng1, Rng2>)
constexpr void operator()(
Rng1 && actual, Rng2 && expected,
source_location sloc = source_location::current()) const
{
auto begin0 = ranges::begin(actual);
auto end0 = ranges::end(actual);
auto begin1 = ranges::begin(expected);
auto end1 = ranges::end(expected);
for(; begin0 != end0 && begin1 != end1; ++begin0, ++begin1)
(*this)(*begin0, *begin1, sloc);
CHECK_SLOC(sloc, begin0 == end0);
CHECK_SLOC(sloc, begin1 == end1);
}
CPP_template(typename Rng, typename Val)(
requires ranges::input_range<Rng>)
constexpr void operator()(
Rng && actual, std::initializer_list<Val> && expected,
source_location sloc = source_location::current()) const
{
(*this)(actual, expected, sloc);
}
};
inline namespace function_objects
{
RANGES_INLINE_VARIABLE(check_equal_fn, check_equal)
}
template<typename Expected, typename Actual>
constexpr void has_type(Actual &&)
{
static_assert(std::is_same<Expected, Actual>::value, "Not the same");
}
template<ranges::cardinality Expected,
typename Rng,
ranges::cardinality Actual = ranges::range_cardinality<Rng>::value>
constexpr void has_cardinality(Rng &&)
{
static_assert(Actual == Expected, "Unexpected cardinality");
}
template<typename T>
constexpr T & as_lvalue(T && t)
{
return t;
}
// A simple, light-weight, non-owning reference to a type-erased function.
template<typename Sig>
struct function_ref;
template<typename Ret, typename... Args>
struct function_ref<Ret(Args...)>
{
private:
void const * data_{nullptr};
Ret (*pfun_)(void const *, Args...){nullptr};
template<typename Fun>
static Ret apply_(void const * data, Args... args)
{
return (*static_cast<Fun const *>(data))(args...);
}
public:
function_ref() = default;
template<typename T>
function_ref(T const & t)
: data_(&t)
, pfun_(&apply_<T>)
{}
Ret operator()(Args... args) const
{
return (*pfun_)(data_, args...);
}
};
template<typename T>
struct checker
{
private:
std::function<void(function_ref<void(T)>)> algo_;
public:
explicit checker(std::function<void(function_ref<void(T)>)> algo)
: algo_(std::move(algo))
{}
void check(function_ref<void(T)> const & check) const
{
algo_(check);
}
};
template<bool B, typename T>
meta::if_c<B, T, T const &> rvalue_if(T const & t)
{
return t;
}
template<typename Algo, bool RvalueOK = false>
struct test_range_algo_1
{
private:
Algo algo_;
template<typename I, typename... Rest>
static auto _impl(Algo algo, I first, I last, Rest &&... rest)
-> ::checker<decltype(algo(first, last, rest...))>
{
using S = meta::_t<sentinel_type<I>>;
using R = decltype(algo(first, last, rest...));
auto check_algo = [algo, first, last, rest...](
function_ref<void(R)> const & check) {
check(algo(first, last, rest...));
check(algo(first, S{base(last)}, rest...));
check(
algo(::rvalue_if<RvalueOK>(ranges::make_subrange(first, last)), rest...));
check(algo(::rvalue_if<RvalueOK>(ranges::make_subrange(first, S{base(last)})),
rest...));
};
return ::checker<R>{check_algo};
}
public:
explicit test_range_algo_1(Algo algo)
: algo_(algo)
{}
template<typename I>
auto operator()(I first, I last) const -> ::checker<decltype(algo_(first, last))>
{
return test_range_algo_1::_impl(algo_, first, last);
}
template<typename I, typename T>
auto operator()(I first, I last, T t) const -> ::checker<decltype(algo_(first, last, t))>
{
return test_range_algo_1::_impl(algo_, first, last, t);
}
template<typename I, typename T, typename U>
auto operator()(I first, I last, T t, U u) const
-> ::checker<decltype(algo_(first, last, t, u))>
{
return test_range_algo_1::_impl(algo_, first, last, t, u);
}
template<typename I, typename T, typename U, typename V>
auto operator()(I first, I last, T t, U u, V v) const
-> ::checker<decltype(algo_(first, last, t, u, v))>
{
return test_range_algo_1::_impl(algo_, first, last, t, u, v);
}
};
template<bool RvalueOK = false, typename Algo>
test_range_algo_1<Algo, RvalueOK> make_testable_1(Algo algo)
{
return test_range_algo_1<Algo, RvalueOK>{algo};
}
template<typename Algo, bool RvalueOK1 = false, bool RvalueOK2 = false>
struct test_range_algo_2
{
private:
Algo algo_;
public:
explicit test_range_algo_2(Algo algo)
: algo_(algo)
{}
template<typename I1, typename I2, typename... Rest>
auto operator()(I1 begin1, I1 end1, I2 begin2, I2 end2, Rest &&... rest) const
-> checker<decltype(algo_(begin1, end1, begin2, end2, rest...))>
{
using S1 = meta::_t<sentinel_type<I1>>;
using S2 = meta::_t<sentinel_type<I2>>;
using R = decltype(algo_(begin1, end1, begin2, end2, rest...));
return checker<R>{[algo = algo_, begin1, end1, begin2, end2, rest...](
function_ref<void(R)> const & check) {
check(algo(begin1, end1, begin2, end2, rest...));
check(algo(begin1, S1{base(end1)}, begin2, S2{base(end2)}, rest...));
check(algo(::rvalue_if<RvalueOK1>(ranges::make_subrange(begin1, end1)),
::rvalue_if<RvalueOK2>(ranges::make_subrange(begin2, end2)),
rest...));
check(algo(
::rvalue_if<RvalueOK1>(ranges::make_subrange(begin1, S1{base(end1)})),
::rvalue_if<RvalueOK2>(ranges::make_subrange(begin2, S2{base(end2)})),
rest...));
}};
}
};
template<bool RvalueOK1 = false, bool RvalueOK2 = false, typename Algo>
test_range_algo_2<Algo, RvalueOK1, RvalueOK2> make_testable_2(Algo algo)
{
return test_range_algo_2<Algo, RvalueOK1, RvalueOK2>{algo};
}
// a simple type to test move semantics
struct MoveOnlyString
{
char const * sz_;
MoveOnlyString(char const * sz = "")
: sz_(sz)
{}
MoveOnlyString(MoveOnlyString && that)
: sz_(that.sz_)
{
that.sz_ = "";
}
MoveOnlyString(MoveOnlyString const &) = delete;
MoveOnlyString & operator=(MoveOnlyString && that)
{
sz_ = that.sz_;
that.sz_ = "";
return *this;
}
MoveOnlyString & operator=(MoveOnlyString const &) = delete;
bool operator==(MoveOnlyString const & that) const
{
return 0 == std::strcmp(sz_, that.sz_);
}
bool operator<(const MoveOnlyString & that) const
{
return std::strcmp(sz_, that.sz_) < 0;
}
bool operator!=(MoveOnlyString const & that) const
{
return !(*this == that);
}
friend std::ostream & operator<<(std::ostream & sout, MoveOnlyString const & str)
{
return sout << '"' << str.sz_ << '"';
}
};
RANGES_DIAGNOSTIC_POP
#endif
|
0 | repos/range-v3 | repos/range-v3/test/multiple2.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <range/v3/all.hpp>
#include "./simple_test.hpp"
#include "./test_utils.hpp"
#include "./test_iterators.hpp"
int main()
{
return ::test_result();
}
|
0 | repos/range-v3 | repos/range-v3/test/test_iterators.hpp | //===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef RANGES_TEST_ITERATORS_HPP
#define RANGES_TEST_ITERATORS_HPP
#include <iterator>
#include <range/v3/range/dangling.hpp>
template<class It, bool Sized = false>
class Sentinel;
template<class It>
class OutputIterator;
template<class It, bool Sized = false>
class InputIterator;
template<class It, bool Sized = false>
class ForwardIterator;
template<class It, bool Sized = false>
class BidirectionalIterator;
template<class It>
class RandomAccessIterator;
template<class Iter, bool Sized>
constexpr /*c++14*/ Iter base(Sentinel<Iter, Sized> i) { return i.base(); }
template<class Iter>
constexpr /*c++14*/ Iter base(OutputIterator<Iter> i) { return i.base(); }
template<class Iter, bool Sized>
constexpr /*c++14*/ Iter base(InputIterator<Iter, Sized> i) { return i.base(); }
template<class Iter, bool Sized>
constexpr /*c++14*/ Iter base(ForwardIterator<Iter, Sized> i) { return i.base(); }
template<class Iter, bool Sized>
constexpr /*c++14*/ Iter base(BidirectionalIterator<Iter, Sized> i) { return i.base(); }
template<class Iter>
constexpr /*c++14*/ Iter base(RandomAccessIterator<Iter> i) { return i.base(); }
template<class Iter> // everything else
constexpr /*c++14*/ Iter base(Iter i) { return i; }
template<class It, bool Sized>
class Sentinel
{
It it_;
public:
constexpr /*c++14*/ Sentinel() : it_() {}
constexpr /*c++14*/ explicit Sentinel(It it) : it_(it) {}
constexpr /*c++14*/ It base() const { return it_; }
constexpr /*c++14*/ friend bool operator==(const Sentinel& x, const Sentinel& y)
{
RANGES_ENSURE(x.it_ == y.it_);
return true;
}
constexpr /*c++14*/ friend bool operator!=(const Sentinel& x, const Sentinel& y)
{
RANGES_ENSURE(x.it_ == y.it_);
return false;
}
template<typename I>
constexpr /*c++14*/ friend bool operator==(const I& x, const Sentinel& y)
{
using ::base;
return base(x) == y.it_;
}
template<typename I>
constexpr /*c++14*/ friend bool operator!=(const I& x, const Sentinel& y)
{
return !(x == y);
}
template<typename I>
constexpr /*c++14*/ friend bool operator==(const Sentinel& x, const I& y)
{
using ::base;
return x.it_ == base(y);
}
template<typename I>
constexpr /*c++14*/ friend bool operator!=(const Sentinel& x, const I& y)
{
return !(x == y);
}
};
// For making sized iterator ranges:
template<template<typename> class I, typename It>
constexpr /*c++14*/
auto CPP_auto_fun(operator-)(Sentinel<It, true> last, I<It> first)
(
return base(last) - base(first)
)
template<template<typename> class I, typename It>
constexpr /*c++14*/
auto CPP_auto_fun(operator-)(I<It> first, Sentinel<It, true> last)
(
return base(first) - base(last)
)
template<class It>
class OutputIterator
{
It it_;
template<class U> friend class OutputIterator;
public:
typedef std::output_iterator_tag iterator_category;
typedef void value_type;
typedef typename std::iterator_traits<It>::difference_type difference_type;
typedef It pointer;
typedef typename std::iterator_traits<It>::reference reference;
constexpr /*c++14*/ It base() const {return it_;}
constexpr /*c++14*/ OutputIterator () {}
constexpr /*c++14*/ explicit OutputIterator(It it) : it_(it) {}
template<class U, class = typename std::enable_if<std::is_convertible<U, It>{}>::type>
constexpr /*c++14*/
OutputIterator(const OutputIterator<U>& u) :it_(u.it_) {}
constexpr /*c++14*/ reference operator*() const {return *it_;}
constexpr /*c++14*/ OutputIterator& operator++() {++it_; return *this;}
constexpr /*c++14*/ OutputIterator operator++(int)
{OutputIterator tmp(*this); ++(*this); return tmp;}
};
template<class It, bool Sized>
class InputIterator
{
It it_;
template<class, bool> friend class InputIterator;
public:
typedef std::input_iterator_tag iterator_category;
typedef typename std::iterator_traits<It>::value_type value_type;
typedef typename std::iterator_traits<It>::difference_type difference_type;
typedef It pointer;
typedef typename std::iterator_traits<It>::reference reference;
constexpr /*c++14*/ It base() const {return it_;}
constexpr /*c++14*/ InputIterator() : it_() {}
constexpr /*c++14*/ explicit InputIterator(It it) : it_(it) {}
template<class U, bool USized>
constexpr /*c++14*/ CPP_ctor(InputIterator)(const InputIterator<U, USized>& u)(
requires (std::is_convertible<U, It>::value)) :it_(u.it_) {}
constexpr /*c++14*/ reference operator*() const {return *it_;}
constexpr /*c++14*/ pointer operator->() const {return it_;}
constexpr /*c++14*/ InputIterator& operator++() {++it_; return *this;}
constexpr /*c++14*/ InputIterator operator++(int)
{InputIterator tmp(*this); ++(*this); return tmp;}
constexpr /*c++14*/
friend bool operator==(const InputIterator& x, const InputIterator& y)
{return x.it_ == y.it_;}
constexpr /*c++14*/
friend bool operator!=(const InputIterator& x, const InputIterator& y)
{return !(x == y);}
template<bool B = Sized, meta::if_c<B, int> = 42>
constexpr /*c++14*/
friend difference_type operator-(const InputIterator& x, const InputIterator& y)
{return x.it_ - y.it_;}
};
template<class T, bool TSized, class U, bool USized>
constexpr /*c++14*/
bool
operator==(const InputIterator<T, TSized>& x, const InputIterator<U, USized>& y)
{
return x.base() == y.base();
}
template<class T, bool TSized, class U, bool USized>
constexpr /*c++14*/
bool
operator!=(const InputIterator<T, TSized>& x, const InputIterator<U, USized>& y)
{
return !(x == y);
}
template<class It, bool Sized>
class ForwardIterator
{
It it_;
template<class, bool> friend class ForwardIterator;
public:
typedef std::forward_iterator_tag iterator_category;
typedef typename std::iterator_traits<It>::value_type value_type;
typedef typename std::iterator_traits<It>::difference_type difference_type;
typedef It pointer;
typedef typename std::iterator_traits<It>::reference reference;
constexpr /*c++14*/ It base() const {return it_;}
constexpr /*c++14*/ ForwardIterator() : it_() {}
constexpr /*c++14*/ explicit ForwardIterator(It it) : it_(it) {}
template<class U, bool USized>
constexpr /*c++14*/ CPP_ctor(ForwardIterator)(const ForwardIterator<U, USized>& u)(
requires (std::is_convertible<U, It>::value)) :it_(u.it_) {}
constexpr /*c++14*/ reference operator*() const {return *it_;}
constexpr /*c++14*/ pointer operator->() const {return it_;}
constexpr /*c++14*/ ForwardIterator& operator++() {++it_; return *this;}
constexpr /*c++14*/ ForwardIterator operator++(int)
{ForwardIterator tmp(*this); ++(*this); return tmp;}
constexpr /*c++14*/
friend bool operator==(const ForwardIterator& x, const ForwardIterator& y)
{return x.it_ == y.it_;}
constexpr /*c++14*/
friend bool operator!=(const ForwardIterator& x, const ForwardIterator& y)
{return !(x == y);}
};
template<class T, bool TSized, class U, bool USized>
constexpr /*c++14*/
bool
operator==(const ForwardIterator<T, TSized>& x, const ForwardIterator<U, USized>& y)
{
return x.base() == y.base();
}
template<class T, bool TSized, class U, bool USized>
constexpr /*c++14*/
bool
operator!=(const ForwardIterator<T, TSized>& x, const ForwardIterator<U, USized>& y)
{
return !(x == y);
}
template<class It, bool Sized>
class BidirectionalIterator
{
It it_;
template<class, bool> friend class BidirectionalIterator;
public:
typedef std::bidirectional_iterator_tag iterator_category;
typedef typename std::iterator_traits<It>::value_type value_type;
typedef typename std::iterator_traits<It>::difference_type difference_type;
typedef It pointer;
typedef typename std::iterator_traits<It>::reference reference;
constexpr /*c++14*/ It base() const {return it_;}
constexpr /*c++14*/ BidirectionalIterator() : it_() {}
constexpr /*c++14*/ explicit BidirectionalIterator(It it) : it_(it) {}
template<class U, bool USized>
constexpr /*c++14*/ CPP_ctor(BidirectionalIterator)(const BidirectionalIterator<U, USized>& u)(
requires (std::is_convertible<U, It>::value)) :it_(u.it_) {}
constexpr /*c++14*/ reference operator*() const {return *it_;}
constexpr /*c++14*/ pointer operator->() const {return it_;}
constexpr /*c++14*/ BidirectionalIterator& operator++() {++it_; return *this;}
constexpr /*c++14*/ BidirectionalIterator operator++(int)
{BidirectionalIterator tmp(*this); ++(*this); return tmp;}
constexpr /*c++14*/ BidirectionalIterator& operator--() {--it_; return *this;}
constexpr /*c++14*/ BidirectionalIterator operator--(int)
{BidirectionalIterator tmp(*this); --(*this); return tmp;}
};
template<class T, bool TSized, class U, bool USized>
constexpr /*c++14*/
bool
operator==(const BidirectionalIterator<T, TSized>& x, const BidirectionalIterator<U, USized>& y)
{
return x.base() == y.base();
}
template<class T, bool TSized, class U, bool USized>
constexpr /*c++14*/
bool
operator!=(const BidirectionalIterator<T, TSized>& x, const BidirectionalIterator<U, USized>& y)
{
return !(x == y);
}
template<class It>
class RandomAccessIterator
{
It it_;
template<class U> friend class RandomAccessIterator;
public:
typedef std::random_access_iterator_tag iterator_category;
typedef typename std::iterator_traits<It>::value_type value_type;
typedef typename std::iterator_traits<It>::difference_type difference_type;
typedef It pointer;
typedef typename std::iterator_traits<It>::reference reference;
constexpr /*c++14*/ It base() const {return it_;}
constexpr /*c++14*/ RandomAccessIterator() : it_() {}
constexpr /*c++14*/ explicit RandomAccessIterator(It it) : it_(it) {}
template<class U>
constexpr /*c++14*/ CPP_ctor(RandomAccessIterator)(const RandomAccessIterator<U>& u)(
requires (std::is_convertible<U, It>::value)) :it_(u.it_) {}
constexpr /*c++14*/ reference operator*() const {return *it_;}
constexpr /*c++14*/ pointer operator->() const {return it_;}
constexpr /*c++14*/ RandomAccessIterator& operator++() {++it_; return *this;}
constexpr /*c++14*/ RandomAccessIterator operator++(int)
{RandomAccessIterator tmp(*this); ++(*this); return tmp;}
constexpr /*c++14*/ RandomAccessIterator& operator--() {--it_; return *this;}
constexpr /*c++14*/ RandomAccessIterator operator--(int)
{RandomAccessIterator tmp(*this); --(*this); return tmp;}
constexpr /*c++14*/
RandomAccessIterator& operator+=(difference_type n) {it_ += n; return *this;}
constexpr /*c++14*/
RandomAccessIterator operator+(difference_type n) const
{RandomAccessIterator tmp(*this); tmp += n; return tmp;}
constexpr /*c++14*/
friend RandomAccessIterator operator+(difference_type n, RandomAccessIterator x)
{x += n; return x;}
constexpr /*c++14*/
RandomAccessIterator& operator-=(difference_type n) {return *this += -n;}
constexpr /*c++14*/
RandomAccessIterator operator-(difference_type n) const
{RandomAccessIterator tmp(*this); tmp -= n; return tmp;}
constexpr /*c++14*/
reference operator[](difference_type n) const {return it_[n];}
};
template<class T, class U>
constexpr /*c++14*/
bool
operator==(const RandomAccessIterator<T>& x, const RandomAccessIterator<U>& y)
{
return x.base() == y.base();
}
template<class T, class U>
constexpr /*c++14*/
bool
operator!=(const RandomAccessIterator<T>& x, const RandomAccessIterator<U>& y)
{
return !(x == y);
}
template<class T, class U>
constexpr /*c++14*/
bool
operator<(const RandomAccessIterator<T>& x, const RandomAccessIterator<U>& y)
{
return x.base() < y.base();
}
template<class T, class U>
constexpr /*c++14*/
bool
operator<=(const RandomAccessIterator<T>& x, const RandomAccessIterator<U>& y)
{
return !(y < x);
}
template<class T, class U>
constexpr /*c++14*/
bool
operator>(const RandomAccessIterator<T>& x, const RandomAccessIterator<U>& y)
{
return y < x;
}
template<class T, class U>
constexpr /*c++14*/
bool
operator>=(const RandomAccessIterator<T>& x, const RandomAccessIterator<U>& y)
{
return !(x < y);
}
template<class T, class U>
constexpr /*c++14*/
auto CPP_auto_fun(operator-)(const RandomAccessIterator<T>& x, const RandomAccessIterator<U>& y)
(
return x.base() - y.base()
)
template<typename It, bool Sized = false>
struct sentinel_type
{
using type = It;
};
template<typename T, bool Sized>
struct sentinel_type<T*, Sized>
{
using type = Sentinel<T*, Sized>;
};
template<template<typename> class I, typename It, bool Sized>
struct sentinel_type<I<It>, Sized>
{
using type = Sentinel<It, Sized>;
};
template<class I, class S>
struct TestRange
{
I first;
S second;
constexpr I begin() const { return first; }
constexpr S end() const { return second; }
};
template<class I, class S>
TestRange<I, S> MakeTestRange(I i, S s)
{
return {i, s};
}
template<typename T>
constexpr bool is_dangling(T)
{
return false;
}
constexpr bool is_dangling(::ranges::dangling)
{
return true;
}
#endif // RANGES_TEST_ITERATORS_HPP
|
0 | repos/range-v3 | repos/range-v3/test/multiple1.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <range/v3/all.hpp>
#include "./simple_test.hpp"
#include "./test_utils.hpp"
#include "./test_iterators.hpp"
|
0 | repos/range-v3 | repos/range-v3/test/bug1335.cpp | #include <vector>
#include <range/v3/action/sort.hpp>
template<typename A, typename B>
constexpr auto operator-(A a, B)
{
return a;
}
int main()
{
std::vector<int> data;
data |= ranges::actions::sort;
}
|
0 | repos/range-v3 | repos/range-v3/test/config.cpp | // Range v3 library
//
// Copyright Casey Carter 2016
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <range/v3/detail/config.hpp>
RANGES_DEPRECATED("compile test for \"RANGES_DEPRECATED\"") void foo() {}
int main()
{
return 0;
}
|
0 | repos/range-v3 | repos/range-v3/test/bug474.cpp | // Range v3 library
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <vector>
#include <range/v3/view/any_view.hpp>
#include <range/v3/algorithm/for_each.hpp>
struct Foo {
Foo() = default;
Foo(Foo const&) = default;
virtual ~Foo() = default;
virtual void foo() = 0;
};
struct Bar : public Foo {
virtual void foo() override {}
};
int main()
{
std::vector<Bar> bars { Bar() };
ranges::any_view<Foo &> foos = bars;
ranges::for_each(foos, [] (Foo & foo) {
foo.foo();
});
}
|
0 | repos/range-v3 | repos/range-v3/test/debug_view.hpp | // Range v3 library
//
// Copyright Casey Carter 2017
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
#ifndef RANGES_TEST_DEBUG_VIEW_HPP
#define RANGES_TEST_DEBUG_VIEW_HPP
#include <cstddef>
#include <atomic>
#include <memory>
#include <range/v3/iterator/operations.hpp>
#include <range/v3/utility/swap.hpp>
template<typename T, bool Sized = true>
struct debug_input_view : ranges::view_base
{
static_assert(std::is_object<T>::value, "");
using index_t = std::ptrdiff_t;
using version_t = long;
struct data
{
T *const first_;
index_t const n_;
std::atomic<index_t> offset_ {-1};
data(T *p, index_t n)
: first_(p), n_(n)
{
RANGES_ENSURE(n >= 0);
RANGES_ENSURE(p || !n);
}
};
std::shared_ptr<data> data_{};
version_t version_ = 0;
debug_input_view() = default;
debug_input_view(T* p, index_t size)
: data_(std::make_shared<data>(p, size))
{}
template<index_t N>
debug_input_view(T (&data)[N])
: debug_input_view{data, N}
{}
debug_input_view(debug_input_view const &that) = default;
debug_input_view &operator=(debug_input_view const &that)
{
data_ = that.data_;
++version_; // invalidate outstanding iterators
return *this;
}
struct sentinel
{
debug_input_view *view_ = nullptr;
version_t version_ = 0;
sentinel() = default;
explicit constexpr sentinel(debug_input_view &view) noexcept
: view_{&view}, version_{view.version_}
{}
};
struct iterator
{
using iterator_category = std::input_iterator_tag;
using value_type = meta::_t<std::remove_cv<T>>;
using difference_type = index_t;
using reference = T &;
using pointer = T *;
debug_input_view *view_ = nullptr;
version_t version_ = 0;
index_t offset_ = -1;
iterator() = default;
explicit constexpr iterator(debug_input_view &view) noexcept
: view_{&view}, version_{view.version_}
, offset_{view.data_ ? view.data_->offset_.load() : -1}
{}
void check_current() const noexcept
{
RANGES_ENSURE(view_);
RANGES_ENSURE(view_->version_ == version_);
RANGES_ENSURE(view_->data_);
RANGES_ENSURE(view_->data_->offset_ == offset_);
}
void check_dereferenceable() const noexcept
{
check_current();
RANGES_ENSURE(view_->data_->offset_ < view_->data_->n_);
}
reference operator*() const noexcept
{
check_dereferenceable();
return view_->data_->first_[offset_];
}
iterator &operator++() noexcept
{
check_dereferenceable();
RANGES_ENSURE(view_->data_->offset_.compare_exchange_strong(offset_, offset_ + 1));
++offset_;
return *this;
}
void operator++(int) noexcept
{
++*this;
}
friend bool operator==(iterator const &i, sentinel const &s)
{
RANGES_ENSURE(i.view_ == s.view_);
RANGES_ENSURE(i.version_ == s.version_);
i.check_current();
return i.offset_ == i.view_->data_->n_;
}
friend bool operator==(sentinel const &s, iterator const &i)
{
return i == s;
}
friend bool operator!=(iterator const &i, sentinel const &s)
{
return !(i == s);
}
friend bool operator!=(sentinel const &s, iterator const &i)
{
return !(i == s);
}
CPP_member
friend auto operator-(sentinel const& s, iterator const& i) ->
CPP_ret(difference_type)(
requires Sized)
{
RANGES_ENSURE(i.view_ == s.view_);
RANGES_ENSURE(i.version_ == s.version_);
i.check_current();
return i.view_->data_->n_ - i.offset_;
}
CPP_member
friend auto operator-(iterator const& i, sentinel const& s) ->
CPP_ret(difference_type)(
requires Sized)
{
return -(s - i);
}
};
iterator begin() noexcept
{
RANGES_ENSURE(data_);
index_t tmp = -1;
RANGES_ENSURE(data_->offset_.compare_exchange_strong(tmp, 0));
return iterator{*this};
}
sentinel end() noexcept
{
RANGES_ENSURE(data_);
return sentinel{*this};
}
CPP_member
auto size() const noexcept -> CPP_ret(std::size_t)(
requires Sized)
{
RANGES_ENSURE(data_);
RANGES_ENSURE(data_->offset_ == -1);
return static_cast<std::size_t>(data_->n_);
}
};
#endif
|
0 | repos/range-v3 | repos/range-v3/test/simple_test.hpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef RANGES_SIMPLE_TEST_HPP
#define RANGES_SIMPLE_TEST_HPP
#include <cstdlib>
#include <utility>
#include <iostream>
#include <range/v3/detail/config.hpp>
namespace test_impl
{
inline int &test_failures()
{
static int test_failures = 0;
return test_failures;
}
template<typename T>
struct streamable_base
{};
template<typename T>
std::ostream &operator<<(std::ostream &sout, streamable_base<T> const &)
{
return sout << "<non-streamable type>";
}
template<typename T>
struct streamable : streamable_base<T>
{
private:
T const &t_;
public:
explicit streamable(T const &t) : t_(t) {}
template<typename U = T>
friend auto operator<<(std::ostream &sout, streamable const &s) ->
decltype(sout << std::declval<U const &>())
{
return sout << s.t_;
}
};
template<typename T>
streamable<T> stream(T const &t)
{
return streamable<T>{t};
}
template<typename T>
struct R
{
private:
char const *filename_;
int lineno_;
char const *expr_;
T t_;
bool dismissed_ = false;
template<typename U>
void oops(U const &u) const
{
std::cerr
<< "> ERROR: CHECK failed \"" << expr_ << "\"\n"
<< "> \t" << filename_ << '(' << lineno_ << ')' << '\n';
if(dismissed_)
std::cerr
<< "> \tEXPECTED: " << stream(u) << "\n> \tACTUAL: " << stream(t_) << '\n';
++test_failures();
}
void dismiss()
{
dismissed_ = true;
}
template<typename V = T>
auto eval_(int) -> decltype(!std::declval<V&>())
{
RANGES_DIAGNOSTIC_PUSH
RANGES_DIAGNOSTIC_IGNORE_FLOAT_CONVERSION
return !t_;
RANGES_DIAGNOSTIC_POP
}
bool eval_(long)
{
return true;
}
public:
R(char const *filename, int lineno, char const *expr, T &&t)
: filename_(filename), lineno_(lineno), expr_(expr)
, t_(std::forward<T>(t))
{}
R(R const&) = delete;
~R()
{
if(!dismissed_ && eval_(42))
this->oops(42);
}
template<typename U>
void operator==(U const &u)
{
dismiss();
if(!(t_ == u)) this->oops(u);
}
template<typename U>
void operator!=(U const &u)
{
dismiss();
if(!(t_ != u)) this->oops(u);
}
template<typename U>
void operator<(U const &u)
{
dismiss();
if(!(t_ < u)) this->oops(u);
}
template<typename U>
void operator<=(U const &u)
{
dismiss();
if(!(t_ <= u)) this->oops(u);
}
template<typename U>
void operator>(U const &u)
{
dismiss();
if(!(t_ > u)) this->oops(u);
}
template<typename U>
void operator>=(U const &u)
{
dismiss();
if(!(t_ >= u)) this->oops(u);
}
};
struct S
{
private:
char const *filename_;
int lineno_;
char const *expr_;
public:
S(char const *filename, int lineno, char const *expr)
: filename_(filename), lineno_(lineno), expr_(expr)
{}
template<typename T>
R<T> operator->*(T &&t)
{
return {filename_, lineno_, expr_, std::forward<T>(t)};
}
};
constexpr bool static_check(bool b, const char * message)
{
if(!b)
{
// an error about this subexpression not valid in a constant expression
// means the check failed
// the message should be printed in the compiler output
throw std::logic_error{message};
}
return true;
}
} // namespace test_impl
inline int test_result()
{
return ::test_impl::test_failures() ? EXIT_FAILURE : EXIT_SUCCESS;
}
#define CHECK_LINE(file, line, ...) \
(void)(::test_impl::S{file, line, #__VA_ARGS__} ->* __VA_ARGS__) \
/**/
#define CHECK(...) CHECK_LINE(__FILE__, __LINE__, __VA_ARGS__)
#define STR(x) #x
#define STATIC_CHECK_LINE(file, line, ...) \
::test_impl::static_check(__VA_ARGS__, \
"> ERROR: CHECK failed \"" #__VA_ARGS__ "\"> " file "(" STR(line) ")")
#define STATIC_CHECK_IMPL(file, line, ...) \
do \
{ \
constexpr auto _ = STATIC_CHECK_LINE(file, line, __VA_ARGS__); \
(void)_; \
} while(0)
#define STATIC_CHECK_RETURN_IMPL(file, line, ...) \
if (!STATIC_CHECK_LINE(file, line, __VA_ARGS__)) return false
// use that as a standalone check
#define STATIC_CHECK(...) STATIC_CHECK_IMPL(__FILE__, __LINE__, __VA_ARGS__)
// use that in a constexpr test returning bool
#define STATIC_CHECK_RETURN(...) STATIC_CHECK_RETURN_IMPL(__FILE__, __LINE__, __VA_ARGS__)
template<class>
struct undef;
#endif
|
0 | repos/range-v3 | repos/range-v3/test/bug566.cpp | // Range v3 library
//
// Copyright Filip Matner 2017
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <vector>
#include <memory>
#include <range/v3/view/for_each.hpp>
#include <range/v3/view/move.hpp>
#include "./simple_test.hpp"
#include "./test_utils.hpp"
using namespace ranges;
int main()
{
std::vector<std::unique_ptr<int>> d;
d.emplace_back(std::unique_ptr<int>(new int(1)));
d.emplace_back(std::unique_ptr<int>(new int(5)));
d.emplace_back(std::unique_ptr<int>(new int(4)));
auto rng = d | views::move | views::for_each([](std::unique_ptr<int> ptr)
{
return yield(*ptr);
});
check_equal(rng, {1, 5, 4});
return ::test_result();
}
|
0 | repos/range-v3 | repos/range-v3/test/bug1322.cpp | #include <concepts/concepts.hpp>
struct S
{};
template <typename T>
void foobar(T &&) {}
#if CPP_CXX_CONCEPTS
template <typename T>
requires concepts::totally_ordered<T>
void foobar(T &&) {}
#endif
int main()
{
std::pair<S, int> p;
foobar(p);
}
|
0 | repos/range-v3/test | repos/range-v3/test/numeric/inner_product.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Gonzalo Brito Gadeschi 2014
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Implementation based on the code in libc++
// http://http://libcxx.llvm.org/
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <range/v3/core.hpp>
#include <range/v3/numeric/inner_product.hpp>
#include <range/v3/algorithm/equal.hpp>
#include "../simple_test.hpp"
#include "../test_iterators.hpp"
RANGES_DIAGNOSTIC_IGNORE_SIGN_CONVERSION
namespace
{
struct S
{
int i;
};
template<class Iter1, class Iter2, class Sent1 = Iter1>
void test()
{
int a[] = {1, 2, 3, 4, 5, 6};
int b[] = {6, 5, 4, 3, 2, 1};
unsigned sa = sizeof(a) / sizeof(a[0]);
// iterator test:
auto it3 = [](int* b1, int l1, int* b2, int i)
{
return ranges::inner_product(Iter1(b1), Sent1(b1+l1), Iter2(b2), i);
};
CHECK(it3(a, 0, b, 0) == 0);
CHECK(it3(a, 0, b, 10) == 10);
CHECK(it3(a, 1, b, 0) == 6);
CHECK(it3(a, 1, b, 10) == 16);
CHECK(it3(a, 2, b, 0) == 16);
CHECK(it3(a, 2, b, 10) == 26);
CHECK(it3(a, sa, b, 0) == 56);
CHECK(it3(a, sa, b, 10) == 66);
auto it4 = [](int* b1, int l1, int* b2, int i)
{
return ranges::inner_product(Iter1(b1), Sent1(b1+l1), Iter2(b2), Iter2(b2+l1), i);
};
CHECK(it4(a, 0, b, 0) == 0);
CHECK(it4(a, 0, b, 10) == 10);
CHECK(it4(a, 1, b, 0) == 6);
CHECK(it4(a, 1, b, 10) == 16);
CHECK(it4(a, 2, b, 0) == 16);
CHECK(it4(a, 2, b, 10) == 26);
CHECK(it4(a, sa, b, 0) == 56);
CHECK(it4(a, sa, b, 10) == 66);
// rng test:
auto rng3 = [](int* b1, int l1, int* b2, int i)
{
return ranges::inner_product(ranges::make_subrange(Iter1(b1), Sent1(b1+l1)), Iter2(b2), i);
};
CHECK(rng3(a, 0, b, 0) == 0);
CHECK(rng3(a, 0, b, 10) == 10);
CHECK(rng3(a, 1, b, 0) == 6);
CHECK(rng3(a, 1, b, 10) == 16);
CHECK(rng3(a, 2, b, 0) == 16);
CHECK(rng3(a, 2, b, 10) == 26);
CHECK(rng3(a, sa, b, 0) == 56);
CHECK(rng3(a, sa, b, 10) == 66);
auto rng4 = [](int* b1, int l1, int* b2, int i)
{
return ranges::inner_product(ranges::make_subrange(Iter1(b1), Sent1(b1+l1)),
ranges::make_subrange(Iter2(b2), Iter2(b2+l1)), i);
};
CHECK(rng4(a, 0, b, 0) == 0);
CHECK(rng4(a, 0, b, 10) == 10);
CHECK(rng4(a, 1, b, 0) == 6);
CHECK(rng4(a, 1, b, 10) == 16);
CHECK(rng4(a, 2, b, 0) == 16);
CHECK(rng4(a, 2, b, 10) == 26);
CHECK(rng4(a, sa, b, 0) == 56);
CHECK(rng4(a, sa, b, 10) == 66);
// rng + bops:
auto bops = [](int* b1, int l1, int* b2, int i)
{
return ranges::inner_product(ranges::make_subrange(Iter1(b1), Sent1(b1+l1)),
ranges::make_subrange(Iter2(b2), Iter2(b2+l1)), i,
std::multiplies<int>(), std::plus<int>());
};
CHECK(bops(a, 0, b, 1) == 1);
CHECK(bops(a, 0, b, 10) == 10);
CHECK(bops(a, 1, b, 1) == 7);
CHECK(bops(a, 1, b, 10) == 70);
CHECK(bops(a, 2, b, 1) == 49);
CHECK(bops(a, 2, b, 10) == 490);
CHECK(bops(a, sa, b, 1) == 117649);
CHECK(bops(a, sa, b, 10) == 1176490);
}
}
int main()
{
test<InputIterator<const int*>, InputIterator<const int*> >();
test<InputIterator<const int*>, ForwardIterator<const int*> >();
test<InputIterator<const int*>, BidirectionalIterator<const int*> >();
test<InputIterator<const int*>, RandomAccessIterator<const int*> >();
test<InputIterator<const int*>, const int*>();
test<ForwardIterator<const int*>, InputIterator<const int*> >();
test<ForwardIterator<const int*>, ForwardIterator<const int*> >();
test<ForwardIterator<const int*>, BidirectionalIterator<const int*> >();
test<ForwardIterator<const int*>, RandomAccessIterator<const int*> >();
test<ForwardIterator<const int*>, const int*>();
test<BidirectionalIterator<const int*>, InputIterator<const int*> >();
test<BidirectionalIterator<const int*>, ForwardIterator<const int*> >();
test<BidirectionalIterator<const int*>, BidirectionalIterator<const int*> >();
test<BidirectionalIterator<const int*>, RandomAccessIterator<const int*> >();
test<BidirectionalIterator<const int*>, const int*>();
test<RandomAccessIterator<const int*>, InputIterator<const int*> >();
test<RandomAccessIterator<const int*>, ForwardIterator<const int*> >();
test<RandomAccessIterator<const int*>, BidirectionalIterator<const int*> >();
test<RandomAccessIterator<const int*>, RandomAccessIterator<const int*> >();
test<RandomAccessIterator<const int*>, const int*>();
test<const int*, InputIterator<const int*> >();
test<const int*, ForwardIterator<const int*> >();
test<const int*, BidirectionalIterator<const int*> >();
test<const int*, RandomAccessIterator<const int*> >();
test<const int*, const int*>();
// test projections:
{
S a[] = {{1}, {2}, {3}, {4}, {5}, {6}};
S b[] = {{6}, {5}, {4}, {3}, {2}, {1}};
unsigned sa = sizeof(a) / sizeof(a[0]);
using Iter1 = InputIterator<const S*>;
using Sent1 = InputIterator<const S*>;
using Iter2 = Iter1;
// rng + bops:
auto bops = [&](S* b1, int l1, S* b2, int i)
{
return ranges::inner_product(ranges::make_subrange(Iter1(b1), Sent1(b1+l1)),
ranges::make_subrange(Iter2(b2), Iter2(b2+l1)), i,
std::multiplies<int>(), std::plus<int>(),
&S::i, &S::i);
};
CHECK(bops(a, 0, b, 1) == 1);
CHECK(bops(a, 0, b, 10) == 10);
CHECK(bops(a, 1, b, 1) == 7);
CHECK(bops(a, 1, b, 10) == 70);
CHECK(bops(a, 2, b, 1) == 49);
CHECK(bops(a, 2, b, 10) == 490);
CHECK(bops(a, sa, b, 1) == 117649);
CHECK(bops(a, sa, b, 10) == 1176490);
}
{
int a[] = {1, 2, 3, 4, 5, 6};
int b[] = {6, 5, 4, 3, 2, 1};
// raw array test:
CHECK(ranges::inner_product(a, b, 0) == 56);
CHECK(ranges::inner_product(a, b, 10) == 66);
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/numeric/adjacent_difference.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Gonzalo Brito Gadeschi 2014
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Implementation based on the code in libc++
// http://http://libcxx.llvm.org/
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <range/v3/core.hpp>
#include <range/v3/numeric/adjacent_difference.hpp>
#include "../simple_test.hpp"
#include "../test_iterators.hpp"
struct S
{
int i;
};
template<class InIter, class OutIter, class InSent = InIter> void test()
{
using ranges::adjacent_difference;
using ranges::make_subrange;
{ // iterator
int ia[] = {15, 10, 6, 3, 1};
int ir[] = {15, -5, -4, -3, -2};
const unsigned s = sizeof(ia) / sizeof(ia[0]);
int ib[s] = {0};
auto r = adjacent_difference(InIter(ia), InSent(ia + s), OutIter(ib));
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
{ // range + output iterator
int ia[] = {15, 10, 6, 3, 1};
int ir[] = {15, -5, -4, -3, -2};
const unsigned s = sizeof(ia) / sizeof(ia[0]);
int ib[s] = {0};
auto rng = make_subrange(InIter(ia), InSent(ia + s));
auto r = adjacent_difference(rng, OutIter(ib));
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
{ // range + output range
int ia[] = {15, 10, 6, 3, 1};
int ir[] = {15, -5, -4, -3, -2};
const unsigned s = sizeof(ia) / sizeof(ia[0]);
int ib[s] = {0};
auto rng = make_subrange(InIter(ia), InSent(ia + s));
auto orng = make_subrange(OutIter(ib), OutIter(ib + s));
auto r = adjacent_difference(rng, orng);
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
{
int ia[] = {15, 10, 6, 3, 1};
int ir[] = {15, 25, 16, 9, 4};
const unsigned s = sizeof(ia) / sizeof(ia[0]);
int ib[s] = {0};
auto rng = make_subrange(InIter(ia), InSent(ia + s));
auto orng = make_subrange(OutIter(ib), OutIter(ib + s));
auto r = adjacent_difference(rng, orng, std::plus<int>());
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
}
int main()
{
test<InputIterator<const int *>, InputIterator<int *>>();
test<InputIterator<const int *>, ForwardIterator<int *>>();
test<InputIterator<const int *>, BidirectionalIterator<int *>>();
test<InputIterator<const int *>, RandomAccessIterator<int *>>();
test<InputIterator<const int *>, int *>();
test<ForwardIterator<const int *>, InputIterator<int *>>();
test<ForwardIterator<const int *>, ForwardIterator<int *>>();
test<ForwardIterator<const int *>, BidirectionalIterator<int *>>();
test<ForwardIterator<const int *>, RandomAccessIterator<int *>>();
test<ForwardIterator<const int *>, int *>();
test<BidirectionalIterator<const int *>, InputIterator<int *>>();
test<BidirectionalIterator<const int *>, ForwardIterator<int *>>();
test<BidirectionalIterator<const int *>, BidirectionalIterator<int *>>();
test<BidirectionalIterator<const int *>, RandomAccessIterator<int *>>();
test<BidirectionalIterator<const int *>, int *>();
test<RandomAccessIterator<const int *>, InputIterator<int *>>();
test<RandomAccessIterator<const int *>, ForwardIterator<int *>>();
test<RandomAccessIterator<const int *>, BidirectionalIterator<int *>>();
test<RandomAccessIterator<const int *>, RandomAccessIterator<int *>>();
test<RandomAccessIterator<const int *>, int *>();
test<const int *, InputIterator<int *>>();
test<const int *, ForwardIterator<int *>>();
test<const int *, BidirectionalIterator<int *>>();
test<const int *, RandomAccessIterator<int *>>();
test<const int *, int *>();
using ranges::adjacent_difference;
{ // Test projections
S ia[] = {{15}, {10}, {6}, {3}, {1}};
int ir[] = {15, -5, -4, -3, -2};
const unsigned s = sizeof(ir) / sizeof(ir[0]);
int ib[s] = {0};
auto r = adjacent_difference(ranges::begin(ia), ranges::begin(ia) + s,
ranges::begin(ib), std::minus<int>(), &S::i);
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
{ // Test BinaryOp
int ia[] = {15, 10, 6, 3, 1};
int ir[] = {15, 25, 16, 9, 4};
const unsigned s = sizeof(ir) / sizeof(ir[0]);
int ib[s] = {0};
auto r = adjacent_difference(ia, ranges::begin(ib), std::plus<int>());
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
{ // Test calling it with an array
int ia[] = {15, 10, 6, 3, 1};
int ir[] = {15, 25, 16, 9, 4};
const unsigned s = sizeof(ir) / sizeof(ir[0]);
int ib[s] = {0};
auto r = adjacent_difference(ia, ib, std::plus<int>());
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/numeric/CMakeLists.txt | set(CMAKE_FOLDER "${CMAKE_FOLDER}/numeric")
rv3_add_test(test.num.accumulate num.accumulate accumulate.cpp)
rv3_add_test(test.num.adjacent_difference num.adjacent_difference adjacent_difference.cpp)
rv3_add_test(test.num.inner_product num.inner_product inner_product.cpp)
rv3_add_test(test.num.iota num.iota iota.cpp)
rv3_add_test(test.num.partial_sum num.partial_sum partial_sum.cpp)
|
0 | repos/range-v3/test | repos/range-v3/test/numeric/partial_sum.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Gonzalo Brito Gadeschi 2014
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Implementation based on the code in libc++
// http://http://libcxx.llvm.org/
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <range/v3/core.hpp>
#include <range/v3/numeric/partial_sum.hpp>
#include <range/v3/view/zip.hpp>
#include "../simple_test.hpp"
#include "../test_iterators.hpp"
struct S
{
int i;
};
template<class InIter, class OutIter, class InSent = InIter> void test()
{
using ranges::partial_sum;
using ranges::make_subrange;
{ // iterator
int ir[] = {1, 3, 6, 10, 15};
const unsigned s = sizeof(ir) / sizeof(ir[0]);
int ia[] = {1, 2, 3, 4, 5};
int ib[s] = {0};
auto r = partial_sum(InIter(ia), InSent(ia + s), OutIter(ib));
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
{ // range + output iterator
int ir[] = {1, 3, 6, 10, 15};
const unsigned s = sizeof(ir) / sizeof(ir[0]);
int ia[] = {1, 2, 3, 4, 5};
int ib[s] = {0};
auto rng = make_subrange(InIter(ia), InSent(ia + s));
auto r = partial_sum(rng, OutIter(ib));
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
{ // range + output range
int ir[] = {1, 3, 6, 10, 15};
const unsigned s = sizeof(ir) / sizeof(ir[0]);
int ia[] = {1, 2, 3, 4, 5};
int ib[s] = {0};
auto rng = make_subrange(InIter(ia), InSent(ia + s));
auto orng = make_subrange(OutIter(ib), OutIter(ib + s));
auto r = partial_sum(rng, orng);
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
{
int ia[] = {1, 2, 3, 4, 5};
int ir[] = {1, -1, -4, -8, -13};
const unsigned s = sizeof(ia) / sizeof(ia[0]);
int ib[s] = {0};
auto rng = make_subrange(InIter(ia), InSent(ia + s));
auto orng = make_subrange(OutIter(ib), OutIter(ib + s));
auto r = partial_sum(rng, orng, std::minus<int>());
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
}
int main()
{
test<InputIterator<const int *>, InputIterator<int *>>();
test<InputIterator<const int *>, ForwardIterator<int *>>();
test<InputIterator<const int *>, BidirectionalIterator<int *>>();
test<InputIterator<const int *>, RandomAccessIterator<int *>>();
test<InputIterator<const int *>, int *>();
test<ForwardIterator<const int *>, InputIterator<int *>>();
test<ForwardIterator<const int *>, ForwardIterator<int *>>();
test<ForwardIterator<const int *>, BidirectionalIterator<int *>>();
test<ForwardIterator<const int *>, RandomAccessIterator<int *>>();
test<ForwardIterator<const int *>, int *>();
test<BidirectionalIterator<const int *>, InputIterator<int *>>();
test<BidirectionalIterator<const int *>, ForwardIterator<int *>>();
test<BidirectionalIterator<const int *>, BidirectionalIterator<int *>>();
test<BidirectionalIterator<const int *>, RandomAccessIterator<int *>>();
test<BidirectionalIterator<const int *>, int *>();
test<RandomAccessIterator<const int *>, InputIterator<int *>>();
test<RandomAccessIterator<const int *>, ForwardIterator<int *>>();
test<RandomAccessIterator<const int *>, BidirectionalIterator<int *>>();
test<RandomAccessIterator<const int *>, RandomAccessIterator<int *>>();
test<RandomAccessIterator<const int *>, int *>();
test<const int *, InputIterator<int *>>();
test<const int *, ForwardIterator<int *>>();
test<const int *, BidirectionalIterator<int *>>();
test<const int *, RandomAccessIterator<int *>>();
test<const int *, int *>();
using ranges::partial_sum;
{ // Test projections
S ia[] = {{1}, {2}, {3}, {4}, {5}};
int ir[] = {1, 3, 6, 10, 15};
const unsigned s = sizeof(ir) / sizeof(ir[0]);
int ib[s] = {0};
auto r = partial_sum(ranges::begin(ia), ranges::begin(ia) + s, ranges::begin(ib),
std::plus<int>(), &S::i);
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
{ // Test BinaryOp
int ia[] = {1, 2, 3, 4, 5};
int ir[] = {1, 2, 6, 24, 120};
const unsigned s = sizeof(ir) / sizeof(ir[0]);
int ib[s] = {0};
auto r = partial_sum(ia, ranges::begin(ib), std::multiplies<int>());
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
{ // Test calling it with an array
int ia[] = {1, 2, 3, 4, 5};
int ir[] = {1, 2, 6, 24, 120};
const unsigned s = sizeof(ir) / sizeof(ir[0]);
int ib[s] = {0};
auto r = partial_sum(ia, ib, std::multiplies<int>());
CHECK(base(r.in) == ia + s);
CHECK(base(r.out) == ib + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ib[i] == ir[i]);
}
}
{ // Test calling it with proxy iterators
using namespace ranges;
int ia[] = {1, 2, 3, 4, 5};
int ib[] = {99, 99, 99, 99, 99};
int ir[] = {1, 2, 6, 24, 120};
const unsigned s = sizeof(ir) / sizeof(ir[0]);
int ic[s] = {0};
auto rng = views::zip(ia, ib);
using CR = iter_common_reference_t<iterator_t<decltype(rng)>>;
auto r = partial_sum(rng, ic, std::multiplies<int>(), [](CR p) {return p.first;});
CHECK(base(r.in) == ranges::begin(rng) + s);
CHECK(base(r.out) == ic + s);
for(unsigned i = 0; i < s; ++i)
{
CHECK(ic[i] == ir[i]);
}
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/numeric/iota.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Gonzalo Brito Gadeschi 2014
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
// Implementation based on the code in libc++
// http://http://libcxx.llvm.org/
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <range/v3/core.hpp>
#include <range/v3/numeric/iota.hpp>
#include <range/v3/algorithm/equal.hpp>
#include "../simple_test.hpp"
#include "../test_iterators.hpp"
template<class Iter, class Sent = Iter>
void test()
{
int ir[] = {5, 6, 7, 8, 9};
constexpr auto s = ranges::size(ir);
{
int ia[] = {1, 2, 3, 4, 5};
ranges::iota(Iter(ia), Sent(ia + s), 5);
CHECK(ranges::equal(ia, ir));
}
{
int ia[] = {1, 2, 3, 4, 5};
auto rng = ranges::make_subrange(Iter(ia), Sent(ia + s));
ranges::iota(rng, 5);
CHECK(ranges::equal(ia, ir));
}
}
int main()
{
test<InputIterator<int*> >();
test<ForwardIterator<int*> >();
test<BidirectionalIterator<int*> >();
test<RandomAccessIterator<int*> >();
test<int*>();
test<InputIterator<int*>, Sentinel<int*> >();
test<ForwardIterator<int*>, Sentinel<int*> >();
test<BidirectionalIterator<int*>, Sentinel<int*> >();
test<RandomAccessIterator<int*>, Sentinel<int*> >();
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/numeric/accumulate.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include <range/v3/core.hpp>
#include <range/v3/numeric/accumulate.hpp>
#include "../simple_test.hpp"
#include "../test_iterators.hpp"
struct S
{
int i;
S add(int j) const
{
return S{i + j};
}
};
template<class Iter, class Sent = Iter>
void test()
{
int ia[] = {1, 2, 3, 4, 5, 6};
constexpr auto sc = ranges::size(ia);
CHECK(ranges::accumulate(Iter(ia), Sent(ia), 0) == 0);
CHECK(ranges::accumulate(Iter(ia), Sent(ia), 10) == 10);
CHECK(ranges::accumulate(Iter(ia), Sent(ia+1), 0) == 1);
CHECK(ranges::accumulate(Iter(ia), Sent(ia+1), 10) == 11);
CHECK(ranges::accumulate(Iter(ia), Sent(ia+2), 0) == 3);
CHECK(ranges::accumulate(Iter(ia), Sent(ia+2), 10) == 13);
CHECK(ranges::accumulate(Iter(ia), Sent(ia+sc), 0) == 21);
CHECK(ranges::accumulate(Iter(ia), Sent(ia+sc), 10) == 31);
using ranges::make_subrange;
CHECK(ranges::accumulate(make_subrange(Iter(ia), Sent(ia)), 0) == 0);
CHECK(ranges::accumulate(make_subrange(Iter(ia), Sent(ia)), 10) == 10);
CHECK(ranges::accumulate(make_subrange(Iter(ia), Sent(ia+1)), 0) == 1);
CHECK(ranges::accumulate(make_subrange(Iter(ia), Sent(ia+1)), 10) == 11);
CHECK(ranges::accumulate(make_subrange(Iter(ia), Sent(ia+2)), 0) == 3);
CHECK(ranges::accumulate(make_subrange(Iter(ia), Sent(ia+2)), 10) == 13);
CHECK(ranges::accumulate(make_subrange(Iter(ia), Sent(ia+sc)), 0) == 21);
CHECK(ranges::accumulate(make_subrange(Iter(ia), Sent(ia+sc)), 10) == 31);
}
int main()
{
test<InputIterator<const int*> >();
test<ForwardIterator<const int*> >();
test<BidirectionalIterator<const int*> >();
test<RandomAccessIterator<const int*> >();
test<const int*>();
test<InputIterator<const int*>, Sentinel<const int*> >();
test<ForwardIterator<const int*>, Sentinel<const int*> >();
test<BidirectionalIterator<const int*>, Sentinel<const int*> >();
test<RandomAccessIterator<const int*>, Sentinel<const int*> >();
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/range/conversion.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <list>
#include <map>
#include <vector>
#include <range/v3/action/sort.hpp>
#include <range/v3/core.hpp>
#include <range/v3/range/conversion.hpp>
#include <range/v3/view/indices.hpp>
#include <range/v3/view/iota.hpp>
#include <range/v3/view/take.hpp>
#include <range/v3/view/transform.hpp>
#include <range/v3/view/zip.hpp>
#include <range/v3/view/reverse.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
template<typename T>
struct vector_like
{
private:
std::vector<T> data_;
public:
using size_type = std::size_t;
using allocator_type = std::allocator<T>;
vector_like() = default;
template<typename I>
vector_like(I first, I last)
: data_(first, last)
{}
template<typename I>
void assign(I first, I last)
{
data_.assign(first, last);
}
auto begin()
{
return data_.begin();
}
auto end()
{
return data_.end();
}
auto begin() const
{
return data_.begin();
}
auto end() const
{
return data_.end();
}
size_type size() const
{
return data_.size();
}
size_type capacity() const
{
return data_.capacity();
}
size_type max_size() const
{
return data_.max_size();
}
auto& operator[](size_type n)
{
return data_[n];
}
auto& operator[](size_type n) const
{
return data_[n];
}
size_type last_reservation{};
size_type reservation_count{};
void reserve(size_type n)
{
data_.reserve(n);
last_reservation = n;
++reservation_count;
}
};
#if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17
template<typename I>
vector_like(I, I) -> vector_like<ranges::iter_value_t<I>>;
template<typename Rng, typename CI = ranges::range_common_iterator_t<Rng>,
typename = decltype(std::map{CI{}, CI{}})>
void test_zip_to_map(Rng && rng, int)
{
using namespace ranges;
#ifdef RANGES_WORKAROUND_MSVC_779708
auto m = static_cast<Rng &&>(rng) | to<std::map>();
#else // ^^^ workaround / no workaround vvv
auto m = static_cast<Rng &&>(rng) | to<std::map>;
#endif // RANGES_WORKAROUND_MSVC_779708
CPP_assert(same_as<decltype(m), std::map<int, int>>);
}
#endif
template<typename Rng>
void test_zip_to_map(Rng &&, long)
{}
template<typename K, typename V>
struct map_like : std::map<K, V>
{
template<typename Iter>
map_like(Iter f, Iter l)
: std::map<K, V>(f, l)
{}
};
#if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17
template<typename Iter>
map_like(Iter, Iter) -> map_like<typename ranges::iter_value_t<Iter>::first_type,
typename ranges::iter_value_t<Iter>::second_type>;
#endif
int main()
{
using namespace ranges;
{
auto lst0 = views::ints | views::transform([](int i) { return i * i; }) |
views::take(10) | to<std::list>();
CPP_assert(same_as<decltype(lst0), std::list<int>>);
::check_equal(lst0, {0, 1, 4, 9, 16, 25, 36, 49, 64, 81});
}
#ifndef RANGES_WORKAROUND_MSVC_779708 // "workaround" is a misnomer; there's no
// workaround.
{
auto lst1 = views::ints | views::transform([](int i) { return i * i; }) |
views::take(10) | to<std::list>;
CPP_assert(same_as<decltype(lst1), std::list<int>>);
::check_equal(lst1, {0, 1, 4, 9, 16, 25, 36, 49, 64, 81});
}
#endif // RANGES_WORKAROUND_MSVC_779708
{
auto vec0 = views::ints | views::transform([](int i) { return i * i; }) |
views::take(10) | to_vector | actions::sort(std::greater<int>{});
CPP_assert(same_as<decltype(vec0), std::vector<int>>);
::check_equal(vec0, {81, 64, 49, 36, 25, 16, 9, 4, 1, 0});
}
{
auto vec1 = views::ints | views::transform([](int i) { return i * i; }) |
views::take(10) | to<std::vector<long>>() |
actions::sort(std::greater<long>{});
CPP_assert(same_as<decltype(vec1), std::vector<long>>);
::check_equal(vec1, {81, 64, 49, 36, 25, 16, 9, 4, 1, 0});
}
#ifndef RANGES_WORKAROUND_MSVC_779708
{
auto vec2 = views::ints | views::transform([](int i) { return i * i; }) |
views::take(10) | to<std::vector<long>> |
actions::sort(std::greater<long>{});
CPP_assert(same_as<decltype(vec2), std::vector<long>>);
::check_equal(vec2, {81, 64, 49, 36, 25, 16, 9, 4, 1, 0});
}
#endif // RANGES_WORKAROUND_MSVC_779708
{
const std::size_t N = 4096;
auto vl = views::iota(0, int{N}) | to<vector_like<int>>();
CPP_assert(same_as<decltype(vl), vector_like<int>>);
CHECK(vl.reservation_count == std::size_t{1});
CHECK(vl.last_reservation == N);
}
// https://github.com/ericniebler/range-v3/issues/1145
{
auto r1 = views::indices(std::uintmax_t{100});
auto r2 = views::zip(r1, r1);
#ifdef RANGES_WORKAROUND_MSVC_779708
auto m = r2 | ranges::to<std::map<std::uintmax_t, std::uintmax_t>>();
#else // ^^^ workaround / no workaround vvv
auto m = r2 | ranges::to<std::map<std::uintmax_t, std::uintmax_t>>;
#endif // RANGES_WORKAROUND_MSVC_779708
CPP_assert(same_as<decltype(m), std::map<std::uintmax_t, std::uintmax_t>>);
}
// Transform a range-of-ranges into a container of containers
{
auto r = views::ints(1, 4) |
views::transform([](int i) { return views::ints(i, i + 3); });
auto m = r | ranges::to<std::vector<std::vector<int>>>();
CPP_assert(same_as<decltype(m), std::vector<std::vector<int>>>);
CHECK(m.size() == 3u);
check_equal(m[0], {1, 2, 3});
check_equal(m[1], {2, 3, 4});
check_equal(m[2], {3, 4, 5});
}
// Use ranges::to in a closure with an action
{
#ifdef RANGES_WORKAROUND_MSVC_779708
auto closure = ranges::to<std::vector>() | actions::sort;
#else // ^^^ workaround / no workaround vvv
auto closure = ranges::to<std::vector> | actions::sort;
#endif // RANGES_WORKAROUND_MSVC_779708
auto r = views::ints(1, 4) | views::reverse;
auto m = r | closure;
CPP_assert(same_as<decltype(m), std::vector<int>>);
CHECK(m.size() == 3u);
check_equal(m, {1, 2, 3});
}
test_zip_to_map(views::zip(views::ints, views::iota(0, 10)), 0);
// https://github.com/ericniebler/range-v3/issues/1544
{
std::vector<std::vector<int>> d;
auto m = views::transform(d, views::all);
auto v = ranges::to<std::vector<std::vector<int>>>(m);
check_equal(d, v);
}
{
std::vector<std::pair<int, int>> v = {{1, 2}, {3, 4}};
auto m1 = ranges::to<map_like<int, int>>(v);
auto m2 = v | ranges::to<map_like<int, int>>();
CPP_assert(same_as<decltype(m1), map_like<int, int>>);
CPP_assert(same_as<decltype(m2), map_like<int, int>>);
check_equal(m1, std::map<int, int>{{1, 2}, {3, 4}});
check_equal(m1, m2);
#if RANGES_CXX_DEDUCTION_GUIDES >= RANGES_CXX_DEDUCTION_GUIDES_17
auto m3 = ranges::to<map_like>(v);
auto m4 = v | ranges::to<map_like>();
CPP_assert(same_as<decltype(m3), map_like<int, int>>);
CPP_assert(same_as<decltype(m4), map_like<int, int>>);
check_equal(m1, m3);
check_equal(m1, m4);
#endif
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/range/access.cpp | // Range v3 library
//
// Copyright Casey Carter 2016
// Copyright Eric Niebler 2018
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <range/v3/range/access.hpp>
#include <range/v3/range/primitives.hpp>
#include <range/v3/view/subrange.hpp>
#include <range/v3/view/ref.hpp>
#include <range/v3/view/iota.hpp>
#include <range/v3/algorithm/find.hpp>
#include <vector>
#include "../simple_test.hpp"
#if defined(__clang__)
RANGES_DIAGNOSTIC_IGNORE("-Wunused-const-variable")
#endif
void test_range_access_ambiguity()
{
std::vector<ranges::reverse_iterator<int*>> vri{};
using namespace ranges;
(void)begin(vri);
(void)end(vri);
(void)cbegin(vri);
(void)cend(vri);
(void)rbegin(vri);
(void)rend(vri);
(void)crbegin(vri);
(void)crend(vri);
}
void test_initializer_list()
{
std::initializer_list<int> il = {0,1,2};
{
int count = 0;
for(auto p = ranges::begin(il), e = ranges::end(il); p != e; ++p) {
CHECK(*p == count++);
}
}
{
int count = 3;
for(auto p = ranges::rbegin(il), e = ranges::rend(il); p != e; ++p) {
CHECK(*p == --count);
}
}
CHECK(ranges::size(il) == std::size_t{3});
CHECK(ranges::data(il) == &*il.begin());
CHECK(ranges::empty(il) == false);
}
template<class Value, typename T, T... Is>
void test_array(std::integer_sequence<T, Is...>)
{
Value a[sizeof...(Is)] = { Is... };
{
int count = 0;
for(auto p = ranges::begin(a), e = ranges::end(a); p != e; ++p) {
CHECK(*p == count++);
}
}
{
int count = sizeof...(Is);
for(auto p = ranges::rbegin(a), e = ranges::rend(a); p != e; ++p) {
CHECK(*p == --count);
}
}
CHECK(ranges::size(a) == sizeof...(Is));
CHECK(ranges::data(a) == a + 0);
CHECK(ranges::empty(a) == false);
}
namespace begin_testing
{
template<class R>
CPP_requires(can_begin_,
requires(R&& r) //
(
ranges::begin((R &&) r)
));
template<class R>
CPP_concept can_begin =
CPP_requires_ref(can_begin_, R);
template<class R>
CPP_requires(can_cbegin_,
requires(R&& r) //
(
ranges::cbegin((R &&) r)
));
template<class R>
CPP_concept can_cbegin =
CPP_requires_ref(can_cbegin_, R);
struct A
{
int* begin();
int* end();
int const * begin() const;
int const * end() const;
};
struct B : A {};
void* begin(B&);
struct C : A {};
void begin(C&);
struct D : A {};
char* begin(D&);
void test()
{
// Valid
CPP_assert(can_begin<int(&)[2]>);
CPP_assert(ranges::same_as<decltype(ranges::begin(std::declval<int(&)[2]>())), int*>);
CPP_assert(can_begin<int const(&)[2]>);
CPP_assert(ranges::same_as<decltype(ranges::begin(std::declval<int const(&)[2]>())), int const *>);
CPP_assert(can_cbegin<int(&)[2]>);
CPP_assert(ranges::same_as<decltype(ranges::cbegin(std::declval<int(&)[2]>())), int const *>);
CPP_assert(can_cbegin<int const(&)[2]>);
CPP_assert(ranges::same_as<decltype(ranges::cbegin(std::declval<int const(&)[2]>())), int const *>);
#ifndef RANGES_WORKAROUND_MSVC_573728
// Ill-formed: array rvalue
CPP_assert(!can_begin<int(&&)[2]>);
CPP_assert(!can_begin<int const(&&)[2]>);
CPP_assert(!can_cbegin<int(&&)[2]>);
CPP_assert(!can_cbegin<int const(&&)[2]>);
#endif // RANGES_WORKAROUND_MSVC_573728
// Valid: only member begin
CPP_assert(can_begin<A&>);
CPP_assert(!can_begin<A>);
CPP_assert(ranges::same_as<decltype(ranges::begin(std::declval<A&>())), int*>);
CPP_assert(can_begin<const A&>);
CPP_assert(!can_begin<const A>);
CPP_assert(ranges::same_as<decltype(ranges::begin(std::declval<const A&>())), int const *>);
// Valid: Both member and non-member begin, but non-member returns non-Iterator.
CPP_assert(can_begin<B&>);
CPP_assert(!can_begin<B>);
CPP_assert(ranges::same_as<decltype(ranges::begin(std::declval<B&>())), int*>);
CPP_assert(can_begin<const B&>);
CPP_assert(!can_begin<const B>);
CPP_assert(ranges::same_as<decltype(ranges::begin(std::declval<const B&>())), int const *>);
// Valid: Both member and non-member begin, but non-member returns non-Iterator.
CPP_assert(can_begin<C&>);
CPP_assert(!can_begin<C>);
CPP_assert(can_begin<const C&>);
CPP_assert(!can_begin<const C>);
// Valid: Prefer member begin
CPP_assert(can_begin<D&>);
CPP_assert(!can_begin<D>);
CPP_assert(ranges::same_as<int*, decltype(ranges::begin(std::declval<D&>()))>);
CPP_assert(can_begin<const D&>);
CPP_assert(!can_begin<const D>);
CPP_assert(ranges::same_as<int const *, decltype(ranges::begin(std::declval<const D&>()))>);
{
using T = std::initializer_list<int>;
// Valid: begin accepts lvalue initializer_list
CPP_assert(ranges::same_as<int const *, decltype(ranges::begin(std::declval<T&>()))>);
CPP_assert(ranges::same_as<int const *, decltype(ranges::begin(std::declval<const T&>()))>);
CPP_assert(!can_begin<T>);
CPP_assert(!can_begin<T const>);
}
CPP_assert(can_begin<ranges::subrange<int*, int*>&>);
CPP_assert(can_begin<const ranges::subrange<int*, int*>&>);
CPP_assert(can_begin<ranges::subrange<int*, int*>>);
CPP_assert(can_begin<const ranges::subrange<int*, int*>>);
CPP_assert(can_cbegin<ranges::subrange<int*, int*>&>);
CPP_assert(can_cbegin<const ranges::subrange<int*, int*>&>);
CPP_assert(can_cbegin<ranges::subrange<int*, int*>>);
CPP_assert(can_cbegin<const ranges::subrange<int*, int*>>);
CPP_assert(can_begin<ranges::ref_view<int[5]>&>);
CPP_assert(can_begin<const ranges::ref_view<int[5]>&>);
CPP_assert(can_begin<ranges::ref_view<int[5]>>);
CPP_assert(can_begin<const ranges::ref_view<int[5]>>);
CPP_assert(can_cbegin<ranges::ref_view<int[5]>&>);
CPP_assert(can_cbegin<const ranges::ref_view<int[5]>&>);
CPP_assert(can_cbegin<ranges::ref_view<int[5]>>);
CPP_assert(can_cbegin<const ranges::ref_view<int[5]>>);
// TODO
// CPP_assert(can_begin<ranges::iota_view<int, int>&>);
// CPP_assert(can_begin<const ranges::iota_view<int, int>&>);
// CPP_assert(can_begin<ranges::iota_view<int, int>>);
// CPP_assert(can_begin<const ranges::iota_view<int, int>>);
// CPP_assert(can_cbegin<ranges::iota_view<int, int>&>);
// CPP_assert(can_cbegin<const ranges::iota_view<int, int>&>);
// CPP_assert(can_cbegin<ranges::iota_view<int, int>>);
// CPP_assert(can_cbegin<const ranges::iota_view<int, int>>);
}
} // namespace begin_testing
namespace X
{
template<class T, std::size_t N>
struct array
{
T elements_[N];
constexpr bool empty() const noexcept { return N == 0; }
constexpr T* data() noexcept { return elements_; }
constexpr T const *data() const noexcept { return elements_; }
};
template<class T, std::size_t N>
constexpr T* begin(array<T, N> &a) noexcept { return a.elements_; }
template<class T, std::size_t N>
constexpr T* end(array<T, N> &a) noexcept { return a.elements_ + N; }
template<class T, std::size_t N>
constexpr T const *begin(array<T, N> const &a) noexcept { return a.elements_; }
template<class T, std::size_t N>
constexpr T const *end(array<T, N> const &a) noexcept { return a.elements_ + N; }
} // namespace X
using I = int*;
using CI = int const *;
CPP_assert(ranges::input_or_output_iterator<I>);
CPP_assert(ranges::input_or_output_iterator<CI>);
#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201603L
void test_string_view_p0970()
{
// basic_string_views are non-dangling
using I2 = ranges::iterator_t<std::string_view>;
CPP_assert(ranges::same_as<I2, decltype(ranges::begin(std::declval<std::string_view>()))>);
CPP_assert(ranges::same_as<I2, decltype(ranges::end(std::declval<std::string_view>()))>);
CPP_assert(ranges::same_as<I2, decltype(ranges::begin(std::declval<const std::string_view>()))>);
CPP_assert(ranges::same_as<I2, decltype(ranges::end(std::declval<const std::string_view>()))>);
{
const char hw[] = "Hello, World!";
auto result = ranges::find(std::string_view{hw}, 'W');
CPP_assert(ranges::same_as<I2, decltype(result)>);
CHECK(result == std::string_view{hw}.begin() + 7);
}
}
#endif
int main()
{
using namespace ranges;
static constexpr X::array<int, 4> some_ints = {{0,1,2,3}};
CPP_assert(begin_testing::can_begin<X::array<int, 4> &>);
CPP_assert(begin_testing::can_begin<X::array<int, 4> const &>);
CPP_assert(!begin_testing::can_begin<X::array<int, 4>>);
CPP_assert(!begin_testing::can_begin<X::array<int, 4> const>);
CPP_assert(begin_testing::can_cbegin<X::array<int, 4> &>);
CPP_assert(begin_testing::can_cbegin<X::array<int, 4> const &>);
CPP_assert(!begin_testing::can_cbegin<X::array<int, 4>>);
CPP_assert(!begin_testing::can_cbegin<X::array<int, 4> const>);
constexpr auto first = begin(some_ints);
constexpr auto last = end(some_ints);
CPP_assert(ranges::same_as<const CI, decltype(first)>);
CPP_assert(ranges::same_as<const CI, decltype(last)>);
static_assert(first == cbegin(some_ints), "");
static_assert(last == cend(some_ints), "");
static_assert(noexcept(begin(some_ints)), "");
static_assert(noexcept(end(some_ints)), "");
static_assert(noexcept(cbegin(some_ints)), "");
static_assert(noexcept(cend(some_ints)), "");
static_assert(noexcept(empty(some_ints)), "");
static_assert(noexcept(data(some_ints)), "");
constexpr bool output = false;
static_assert(!empty(some_ints), "");
if(output)
std::cout << '{';
auto is_first = true;
auto count = 0;
for(auto&& i : some_ints)
{
CHECK(i == count++);
if(is_first)
is_first = false;
else
if(output) std::cout << ", ";
if(output) std::cout << i;
}
if(output)
std::cout << "}\n";
test_initializer_list();
test_array<int>(std::make_integer_sequence<int, 3>{});
test_array<int const>(std::make_integer_sequence<int, 3>{});
begin_testing::test();
#if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201603L
test_string_view_p0970();
#endif
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/range/CMakeLists.txt | set(CMAKE_FOLDER "${CMAKE_FOLDER}/range")
rv3_add_test(test.range.access range.access access.cpp)
rv3_add_test(test.range.conversion range.conversion conversion.cpp)
rv3_add_test(test.range.index range.index index.cpp)
rv3_add_test(test.range.operations range.operations operations.cpp)
|
0 | repos/range-v3/test | repos/range-v3/test/range/operations.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Michel Morin 2014
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <forward_list>
#include <list>
#include <vector>
#include <limits>
#include <range/v3/core.hpp>
#include <range/v3/view/iota.hpp>
#include <range/v3/view/take_while.hpp>
#include "../array.hpp"
#include "../simple_test.hpp"
#include "../test_utils.hpp"
template<typename I, typename S>
void test_iterators(I first, S last, ranges::iter_difference_t<I> n)
{
using namespace ranges;
CHECK(distance(first, last) == n);
CHECK(distance_compare(first, last, n) == 0);
CHECK(distance_compare(first, last, n - 1) > 0);
CHECK(distance_compare(first, last, n + 1) < 0);
CHECK(distance_compare(first, last, (std::numeric_limits<iter_difference_t<I>>::min)()) > 0);
CHECK(distance_compare(first, last, (std::numeric_limits<iter_difference_t<I>>::max)()) < 0);
}
template<typename Rng>
void test_range(Rng&& rng, ranges::range_difference_t<Rng> n)
{
using namespace ranges;
CHECK(distance(rng) == n);
CHECK(distance_compare(rng, n) == 0);
CHECK(distance_compare(rng, n - 1) > 0);
CHECK(distance_compare(rng, n + 1) < 0);
CHECK(distance_compare(rng, (std::numeric_limits<range_difference_t<Rng>>::min)()) > 0);
CHECK(distance_compare(rng, (std::numeric_limits<range_difference_t<Rng>>::max)()) < 0);
}
template<typename Rng>
void test_infinite_range(Rng&& rng)
{
using namespace ranges;
CHECK(distance_compare(rng, 0) > 0);
CHECK(distance_compare(rng,-1) > 0);
CHECK(distance_compare(rng, 1) > 0);
CHECK(distance_compare(rng, (std::numeric_limits<range_difference_t<Rng>>::min)()) > 0);
if (is_infinite<Rng>::value) {
// For infinite ranges that can be detected by is_infinite<Rng> traits,
// distance_compare can compute the result in constant time.
CHECK(distance_compare(rng, (std::numeric_limits<range_difference_t<Rng>>::max)()) > 0);
}
else {
// For other infinite ranges, comparing to a huge number might take too much time.
// Thus commented out the test.
// CHECK(distance_compare(rng, (std::numeric_limits<range_difference_t<Rng>>::max)()) > 0);
}
}
constexpr bool test_constexpr()
{
using namespace ranges;
auto rng = test::array<int, 10>{{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}};
using Rng = decltype(rng);
auto bit = ranges::begin(rng);
using I = decltype(bit);
auto it = bit + 5;
auto eit = ranges::end(rng);
auto n = ranges::distance(rng);
auto en = ranges::enumerate(rng);
STATIC_CHECK_RETURN(n == 10);
STATIC_CHECK_RETURN(distance(bit, eit) == n);
STATIC_CHECK_RETURN(distance(it, eit) == 5);
STATIC_CHECK_RETURN(distance_compare(bit, eit, n) == 0);
STATIC_CHECK_RETURN(distance_compare(bit, eit, n - 1) > 0);
STATIC_CHECK_RETURN(distance_compare(bit, eit, n + 1) < 0);
STATIC_CHECK_RETURN(distance_compare(bit, eit, (std::numeric_limits<iter_difference_t<I>>::min)()) > 0);
STATIC_CHECK_RETURN(distance_compare(bit, eit, (std::numeric_limits<iter_difference_t<I>>::max)()) < 0);
STATIC_CHECK_RETURN(distance(rng) == n);
STATIC_CHECK_RETURN(distance_compare(rng, n) == 0);
STATIC_CHECK_RETURN(distance_compare(rng, n - 1) > 0);
STATIC_CHECK_RETURN(distance_compare(rng, n + 1) < 0);
STATIC_CHECK_RETURN(distance_compare(rng, (std::numeric_limits<range_difference_t<Rng>>::min)()) > 0);
STATIC_CHECK_RETURN(distance_compare(rng, (std::numeric_limits<range_difference_t<Rng>>::max)()) < 0);
STATIC_CHECK_RETURN(en.first == 10);
STATIC_CHECK_RETURN(en.second == eit);
return true;
}
int main()
{
using namespace ranges;
{
using cont_t = std::vector<int>;
cont_t c {1, 2, 3, 4};
test_range(c, 4);
test_iterators(c.begin(), c.end(), 4);
c.clear();
test_range(c, 0);
test_iterators(c.begin(), c.end(), 0);
}
{
using cont_t = std::list<int>;
cont_t c {1, 2, 3, 4};
test_range(c, 4);
test_iterators(c.begin(), c.end(), 4);
c.clear();
test_range(c, 0);
test_iterators(c.begin(), c.end(), 0);
}
{
using cont_t = std::forward_list<int>;
cont_t c {1, 2, 3, 4};
test_range(c, 4);
test_iterators(c.begin(), c.end(), 4);
c.clear();
test_range(c, 0);
test_iterators(c.begin(), c.end(), 0);
}
{
int a[] = {1, 2, 3, 4};
test_iterators(a + 4, a, -4);
}
{
test_range(views::iota(0) | views::take_while([](int i) { return i < 4; }), 4);
}
{
test_infinite_range(views::iota(0u));
}
{
STATIC_CHECK(test_constexpr());
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/range/index.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Gonzalo Brito Gadeschi 2017
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <vector>
#include <range/v3/algorithm/equal.hpp>
#include <range/v3/view/c_str.hpp>
#include <range/v3/view/iota.hpp>
#include <range/v3/core.hpp>
#include "../simple_test.hpp"
int main()
{
{
std::vector<int> vi{1,2,3,4};
CHECK(ranges::index(vi, 0) == 1);
CHECK(ranges::index(vi, 1) == 2);
CHECK(ranges::index(vi, 2) == 3);
CHECK(ranges::index(vi, 3) == 4);
CHECK(ranges::at(vi, 0) == 1);
CHECK(ranges::at(vi, 1) == 2);
CHECK(ranges::at(vi, 2) == 3);
CHECK(ranges::at(vi, 3) == 4);
try
{
ranges::at(vi, 4);
CHECK(false);
}
catch(std::out_of_range const& e)
{
CHECK(ranges::equal(ranges::views::c_str(e.what()),
ranges::views::c_str("ranges::at")));
}
try
{
ranges::at(vi, -1);
CHECK(false);
}
catch(std::out_of_range const& e)
{
CHECK(ranges::equal(ranges::views::c_str(e.what()),
ranges::views::c_str("ranges::at")));
}
auto viv = ranges::make_subrange(vi.begin(), vi.end());
CHECK(viv.at(0) == 1);
CHECK(viv.at(1) == 2);
CHECK(viv.at(2) == 3);
CHECK(viv.at(3) == 4);
try
{
viv.at(4);
CHECK(false);
}
catch(std::out_of_range const& e)
{
CHECK(ranges::equal(ranges::views::c_str(e.what()),
ranges::views::c_str("view_interface::at")));
}
try
{
viv.at(-1);
CHECK(false);
}
catch(std::out_of_range const& e)
{
CHECK(ranges::equal(ranges::views::c_str(e.what()),
ranges::views::c_str("view_interface::at")));
}
const auto cviv = viv;
CHECK(cviv.at(0) == 1);
CHECK(cviv.at(1) == 2);
CHECK(cviv.at(2) == 3);
CHECK(cviv.at(3) == 4);
try
{
cviv.at(4);
CHECK(false);
}
catch(std::out_of_range const& e)
{
CHECK(ranges::equal(ranges::views::c_str(e.what()),
ranges::views::c_str("view_interface::at")));
}
try
{
cviv.at(-1);
CHECK(false);
}
catch(std::out_of_range const& e)
{
CHECK(ranges::equal(ranges::views::c_str(e.what()),
ranges::views::c_str("view_interface::at")));
}
}
{
auto rng = ranges::views::ints(std::int64_t{0}, std::numeric_limits<std::int64_t>::max());
CHECK(ranges::index(rng, std::numeric_limits<std::int64_t>::max() - 1) ==
std::numeric_limits<std::int64_t>::max() - 1);
CHECK(ranges::at(rng, std::numeric_limits<std::int64_t>::max() - 1) ==
std::numeric_limits<std::int64_t>::max() - 1);
}
#if RANGES_CXX_CONSTEXPR >= RANGES_CXX_CONSTEXPR_14
{
constexpr int vi[4] = {1, 2, 3, 4};
constexpr int vi0 = ranges::index(vi, 0);
static_assert(vi0 == 1, "");
constexpr int vi1 = ranges::at(vi, 1);
static_assert(vi1 == 2, "");
}
#endif
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/utility/box.cpp | // Range v3 library
//
// Copyright Andrey Diduh 2019
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <range/v3/utility/compressed_pair.hpp>
#include "../simple_test.hpp"
using namespace ranges;
// #https://github.com/ericniebler/range-v3/issues/1093
void test_1093()
{
struct Op {};
struct Op2 {};
struct payload { void* v; };
struct base_adaptor {};
struct RANGES_EMPTY_BASES A : base_adaptor, private box<Op, A> {};
struct RANGES_EMPTY_BASES B : base_adaptor, private box<Op2, B> {};
using P = compressed_pair<A, payload>;
using P2 = compressed_pair<B, P>;
CHECK(sizeof(P) == sizeof(payload));
CHECK(sizeof(P2) == sizeof(P));
}
int main()
{
test_1093();
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/utility/compare.cpp | /// \file
// CPP, the Concepts PreProcessor library
//
// Copyright Eric Niebler 2018-present
// Copyright (c) 2020-present, Google LLC.
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
//
// Project home: https://github.com/ericniebler/range-v3
//
#if __cplusplus > 201703L && __has_include(<compare>) && \
defined(__cpp_concepts) && defined(__cpp_impl_three_way_comparison)
#include <compare>
#include <range/v3/compare.hpp>
#include <range/v3/range_fwd.hpp>
using ranges::same_as;
using ranges::common_comparison_category_t;
static_assert(same_as<common_comparison_category_t<std::partial_ordering>, std::partial_ordering>);
static_assert(same_as<common_comparison_category_t<std::weak_ordering>, std::weak_ordering>);
static_assert(same_as<common_comparison_category_t<std::strong_ordering>, std::strong_ordering>);
static_assert(same_as<common_comparison_category_t<std::partial_ordering, std::strong_ordering>, std::partial_ordering>);
static_assert(same_as<common_comparison_category_t<std::weak_ordering, std::strong_ordering>, std::weak_ordering>);
static_assert(same_as<common_comparison_category_t<std::strong_ordering, std::strong_ordering>, std::strong_ordering>);
static_assert(same_as<common_comparison_category_t<std::weak_ordering, std::strong_ordering, std::partial_ordering>, std::partial_ordering>);
static_assert(same_as<common_comparison_category_t<ranges::less, std::partial_ordering>, void>);
static_assert(same_as<common_comparison_category_t<ranges::less*, std::strong_ordering>, void>);
static_assert(same_as<common_comparison_category_t<ranges::less&, std::strong_ordering, std::partial_ordering>, void>);
static_assert(same_as<common_comparison_category_t<ranges::less(*)(), std::strong_ordering, std::partial_ordering>, void>);
#endif // __cplusplus
int main() {}
|
0 | repos/range-v3/test | repos/range-v3/test/utility/functional.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Casey Carter 2015
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <memory>
#include <range/v3/functional/invoke.hpp>
#include <range/v3/functional/not_fn.hpp>
#include <range/v3/view/filter.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
CPP_assert(ranges::constructible_from<ranges::reference_wrapper<int>, int&>);
CPP_assert(!ranges::constructible_from<ranges::reference_wrapper<int>, int&&>);
CPP_assert(!ranges::constructible_from<ranges::reference_wrapper<int &&>, int&>);
CPP_assert(ranges::constructible_from<ranges::reference_wrapper<int &&>, int&&>);
namespace
{
struct Integer
{
int i;
operator int() const { return i; }
bool odd() const { return (i % 2) != 0; }
};
enum class kind { lvalue, const_lvalue, rvalue, const_rvalue };
std::ostream &operator<<(std::ostream &os, kind k)
{
const char* message = nullptr;
switch (k) {
case kind::lvalue:
message = "lvalue";
break;
case kind::const_lvalue:
message = "const_lvalue";
break;
case kind::rvalue:
message = "rvalue";
break;
case kind::const_rvalue:
message = "const_rvalue";
break;
}
return os << message;
}
kind last_call;
template<kind DisableKind>
struct fn
{
bool operator()() &
{
last_call = kind::lvalue;
return DisableKind != kind::lvalue;
}
bool operator()() const &
{
last_call = kind::const_lvalue;
return DisableKind != kind::const_lvalue;
}
bool operator()() &&
{
last_call = kind::rvalue;
return DisableKind != kind::rvalue;
}
bool operator()() const &&
{
last_call = kind::const_rvalue;
return DisableKind != kind::const_rvalue;
}
};
constexpr struct {
template<typename T>
constexpr T&& operator()(T&& arg) const noexcept {
return (T&&)arg;
}
} h = {};
struct A {
int i = 13;
constexpr int f() const noexcept { return 42; }
constexpr /*c++14*/ int g(int j) { return 2 * j; }
};
constexpr int f() noexcept { return 13; }
constexpr int g(int i) { return 2 * i + 1; }
void test_invoke()
{
CHECK(ranges::invoke(f) == 13);
// CHECK(noexcept(ranges::invoke(f) == 13));
CHECK(ranges::invoke(g, 2) == 5);
CHECK(ranges::invoke(h, 42) == 42);
CHECK(noexcept(ranges::invoke(h, 42) == 42));
{
int i = 13;
CHECK(&ranges::invoke(h, i) == &i);
CHECK(noexcept(&ranges::invoke(h, i) == &i));
}
CHECK(ranges::invoke(&A::f, A{}) == 42);
// CHECK(noexcept(ranges::invoke(&A::f, A{}) == 42));
CHECK(ranges::invoke(&A::g, A{}, 2) == 4);
{
A a;
const auto& ca = a;
CHECK(ranges::invoke(&A::f, a) == 42);
// CHECK(noexcept(ranges::invoke(&A::f, a) == 42));
CHECK(ranges::invoke(&A::f, ca) == 42);
// CHECK(noexcept(ranges::invoke(&A::f, ca) == 42));
CHECK(ranges::invoke(&A::g, a, 2) == 4);
}
{
A a;
const auto& ca = a;
CHECK(ranges::invoke(&A::f, &a) == 42);
// CHECK(noexcept(ranges::invoke(&A::f, &a) == 42));
CHECK(ranges::invoke(&A::f, &ca) == 42);
// CHECK(noexcept(ranges::invoke(&A::f, &ca) == 42));
CHECK(ranges::invoke(&A::g, &a, 2) == 4);
}
{
std::unique_ptr<A> up(new A);
CHECK(ranges::invoke(&A::f, up) == 42);
CHECK(ranges::invoke(&A::g, up, 2) == 4);
}
{
auto sp = std::make_shared<A>();
CHECK(ranges::invoke(&A::f, sp) == 42);
// CHECK(noexcept(ranges::invoke(&A::f, sp) == 42));
CHECK(ranges::invoke(&A::g, sp, 2) == 4);
}
CHECK(ranges::invoke(&A::i, A{}) == 13);
// CHECK(noexcept(ranges::invoke(&A::i, A{}) == 13));
{ int&& tmp = ranges::invoke(&A::i, A{}); (void)tmp; }
{
A a;
const auto& ca = a;
CHECK(ranges::invoke(&A::i, a) == 13);
// CHECK(noexcept(ranges::invoke(&A::i, a) == 13));
CHECK(ranges::invoke(&A::i, ca) == 13);
// CHECK(noexcept(ranges::invoke(&A::i, ca) == 13));
CHECK(ranges::invoke(&A::i, &a) == 13);
// CHECK(noexcept(ranges::invoke(&A::i, &a) == 13));
CHECK(ranges::invoke(&A::i, &ca) == 13);
// CHECK(noexcept(ranges::invoke(&A::i, &ca) == 13));
ranges::invoke(&A::i, a) = 0;
CHECK(a.i == 0);
ranges::invoke(&A::i, &a) = 1;
CHECK(a.i == 1);
CPP_assert(ranges::same_as<decltype(ranges::invoke(&A::i, ca)), const int&>);
CPP_assert(ranges::same_as<decltype(ranges::invoke(&A::i, &ca)), const int&>);
}
{
std::unique_ptr<A> up(new A);
CHECK(ranges::invoke(&A::i, up) == 13);
ranges::invoke(&A::i, up) = 0;
CHECK(up->i == 0);
}
{
auto sp = std::make_shared<A>();
CHECK(ranges::invoke(&A::i, sp) == 13);
ranges::invoke(&A::i, sp) = 0;
CHECK(sp->i == 0);
}
// {
// struct B { int i = 42; constexpr int f() const { return i; } };
// constexpr B b;
// static_assert(b.i == 42, "");
// static_assert(b.f() == 42, "");
// static_assert(ranges::invoke_detail::impl(&B::i, b) == 42, "");
// static_assert(ranges::invoke_detail::impl(&B::i, &b) == 42, "");
// static_assert(ranges::invoke_detail::impl(&B::i, B{}) == 42, "");
// static_assert(ranges::invoke_detail::impl(&B::f, b) == 42, "");
// static_assert(ranges::invoke_detail::impl(&B::f, &b) == 42, "");
// static_assert(ranges::invoke_detail::impl(&B::f, B{}) == 42, "");
// }
}
} // unnamed namespace
int main()
{
{
// Check that not_fn works with callables
Integer some_ints[] = {{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}};
::check_equal(some_ints | ranges::views::filter(ranges::not_fn(&Integer::odd)),
{0,2,4,6});
}
// Check that not_fn forwards value category
{
constexpr auto k = kind::lvalue;
using F = fn<k>;
auto f = ranges::not_fn(F{});
CHECK(f() == true);
CHECK(last_call == k);
}
{
constexpr auto k = kind::const_lvalue;
using F = fn<k>;
auto const f = ranges::not_fn(F{});
CHECK(f() == true);
CHECK(last_call == k);
}
{
constexpr auto k = kind::rvalue;
using F = fn<k>;
auto f = ranges::not_fn(F{});
CHECK(std::move(f)() == true); // xvalue
CHECK(last_call == k);
CHECK(decltype(f){}() == true); // prvalue
CHECK(last_call == k);
}
#ifdef _WIN32
{
// Ensure that invocable accepts pointers to functions with non-default calling conventions.
CPP_assert(ranges::invocable<void(__cdecl*)()>);
CPP_assert(ranges::invocable<void(__stdcall*)()>);
CPP_assert(ranges::invocable<void(__fastcall*)()>);
CPP_assert(ranges::invocable<void(__thiscall*)()>);
#ifndef __MINGW32__
CPP_assert(ranges::invocable<void(__vectorcall*)()>);
#endif
}
#endif // _WIN32
test_invoke();
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/utility/variant.cpp | // Range v3 library
//
// Copyright Eric Niebler 2015-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <vector>
#include <sstream>
#include <iostream>
#include <range/v3/functional/overload.hpp>
#include <range/v3/numeric/accumulate.hpp>
#include <range/v3/utility/variant.hpp>
#include <range/v3/view/concat.hpp>
#include <range/v3/view/partial_sum.hpp>
#include <range/v3/view/transform.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
void bug_1217()
{
std::vector<int> vec;
if(auto tx = vec | ranges::views::transform( [](int){ return 0; } ))
{
auto positions_visited = ranges::views::concat( tx, tx ) | ranges::views::partial_sum;
ranges::accumulate( positions_visited, 0 );
}
}
int main()
{
using namespace ranges;
// Simple variant and access.
{
variant<int, short> v;
CHECK(v.index() == 0u);
auto v2 = v;
CHECK(v2.index() == 0u);
v.emplace<1>((short)2);
CHECK(v.index() == 1u);
CHECK(get<1>(v) == (short)2);
try
{
get<0>(v);
CHECK(false);
}
catch(const bad_variant_access&)
{}
catch(...)
{
CHECK(!(bool)"unknown exception");
}
v = v2;
CHECK(v.index() == 0u);
}
// variant of void
{
variant<void, void> v;
CHECK(v.index() == 0u);
v.emplace<0>();
CHECK(v.index() == 0u);
try
{
// Will only compile if get returns void
v.index() == 0 ? void() : get<0>(v);
}
catch(...)
{
CHECK(false);
}
v.emplace<1>();
CHECK(v.index() == 1u);
try
{
get<0>(v);
CHECK(false);
}
catch(const bad_variant_access&)
{}
catch(...)
{
CHECK(!(bool)"unknown exception");
}
}
// variant of references
{
int i = 42;
std::string s = "hello world";
variant<int&, std::string&> v{emplaced_index<0>, i};
CPP_assert(!default_constructible<variant<int&, std::string&>>);
CHECK(v.index() == 0u);
CHECK(get<0>(v) == 42);
CHECK(&get<0>(v) == &i);
auto const & cv = v;
get<0>(cv) = 24;
CHECK(i == 24);
v.emplace<1>(s);
CHECK(v.index() == 1u);
CHECK(get<1>(v) == "hello world");
CHECK(&get<1>(v) == &s);
get<1>(cv) = "goodbye";
CHECK(s == "goodbye");
}
// Move test 1
{
variant<int, MoveOnlyString> v{emplaced_index<1>, "hello world"};
CHECK(get<1>(v) == "hello world");
MoveOnlyString s = get<1>(std::move(v));
CHECK(s == "hello world");
CHECK(get<1>(v) == "");
v.emplace<1>("goodbye");
CHECK(get<1>(v) == "goodbye");
auto v2 = std::move(v);
CHECK(get<1>(v2) == "goodbye");
CHECK(get<1>(v) == "");
v = std::move(v2);
CHECK(get<1>(v) == "goodbye");
CHECK(get<1>(v2) == "");
}
// Move test 2
{
MoveOnlyString s = "hello world";
variant<MoveOnlyString&> v{emplaced_index<0>, s};
CHECK(get<0>(v) == "hello world");
MoveOnlyString &s2 = get<0>(std::move(v));
CHECK(&s2 == &s);
}
// Apply test 1
{
std::stringstream sout;
variant<int, std::string> v{emplaced_index<1>, "hello"};
auto fun = overload(
[&sout](int&) {sout << "int";},
[&sout](std::string&)->int {sout << "string"; return 42;});
variant<void, int> x = v.visit(fun);
CHECK(sout.str() == "string");
CHECK(x.index() == 1u);
CHECK(get<1>(x) == 42);
}
// Apply test 2
{
std::stringstream sout;
std::string s = "hello";
variant<int, std::string&> const v{emplaced_index<1>, s};
auto fun = overload(
[&sout](int const&) {sout << "int";},
[&sout](std::string&)->int {sout << "string"; return 42;});
variant<void, int> x = v.visit(fun);
CHECK(sout.str() == "string");
CHECK(x.index() == 1u);
CHECK(get<1>(x) == 42);
}
// constexpr variant
{
constexpr variant<int, short> v{emplaced_index<1>, (short)2};
static_assert(v.index() == 1,"");
static_assert(v.valid(),"");
}
// Variant and arrays
{
variant<int[5], std::vector<int>> v{emplaced_index<0>, {1,2,3,4,5}};
int (&rgi)[5] = get<0>(v);
check_equal(rgi, {1,2,3,4,5});
variant<int[5], std::vector<int>> v2{emplaced_index<0>, {}};
int (&rgi2)[5] = get<0>(v2);
check_equal(rgi2, {0,0,0,0,0});
v2 = v;
check_equal(rgi2, {1,2,3,4,5});
struct T
{
T() = delete;
T(int) {}
T(T const &) = default;
T &operator=(T const &) = default;
};
// Should compile and not assert at runtime.
variant<T[5]> vrgt{emplaced_index<0>, {T{42},T{42},T{42},T{42},T{42}}};
(void) vrgt;
}
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/utility/common_type.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <utility>
#include <type_traits>
#include <range/v3/utility/common_type.hpp>
#include <range/v3/utility/common_tuple.hpp>
struct B {};
struct D : B {};
struct noncopyable
{
noncopyable() = default;
noncopyable(noncopyable const &) = delete;
noncopyable(noncopyable &&) = default;
noncopyable &operator=(noncopyable const &) = delete;
noncopyable &operator=(noncopyable &&) = default;
};
struct noncopyable2 : noncopyable
{};
struct X {};
struct Y {};
struct Z {};
namespace concepts
{
template<>
struct common_type<X, Y>
{
using type = Z;
};
template<>
struct common_type<Y, X>
{
using type = Z;
};
}
template<typename T>
struct ConvTo
{
operator T();
};
// Whoops, fails:
static_assert(std::is_same<
ranges::common_type_t<ConvTo<int>, int>,
int
>::value, "");
int main()
{
using namespace ranges;
using namespace detail;
static_assert(std::is_same<common_reference_t<B &, D &>, B &>::value, "");
static_assert(std::is_same<common_reference_t<B &, D const &>, B const &>::value, "");
static_assert(std::is_same<common_reference_t<B &, D const &, D &>, B const &>::value, "");
static_assert(std::is_same<common_reference_t<B const &, D &>, B const &>::value, "");
static_assert(std::is_same<common_reference_t<B &, D &, B &, D &>, B &>::value, "");
static_assert(std::is_same<common_reference_t<B &&, D &&>, B &&>::value, "");
static_assert(std::is_same<common_reference_t<B const &&, D &&>, B const &&>::value, "");
static_assert(std::is_same<common_reference_t<B &&, D const &&>, B const &&>::value, "");
static_assert(std::is_same<common_reference_t<B &, D &&>, B const &>::value, "");
static_assert(std::is_same<common_reference_t<B &, D const &&>, B const &>::value, "");
static_assert(std::is_same<common_reference_t<B const &, D &&>, B const &>::value, "");
static_assert(std::is_same<common_reference_t<B &&, D &>, B const &>::value, "");
static_assert(std::is_same<common_reference_t<B &&, D const &>, B const &>::value, "");
static_assert(std::is_same<common_reference_t<B const &&, D &>, B const &>::value, "");
static_assert(std::is_same<common_reference_t<int, short>, int>::value, "");
static_assert(std::is_same<common_reference_t<int, short &>, int>::value, "");
static_assert(std::is_same<common_reference_t<int &, short &>, int>::value, "");
static_assert(std::is_same<common_reference_t<int &, short>, int>::value, "");
// tricky volatile reference case
static_assert(std::is_same<common_reference_t<int &&, int volatile &>, int>::value, "");
static_assert(std::is_same<common_reference_t<int volatile &, int &&>, int>::value, "");
static_assert(std::is_same<common_reference_t<int const volatile &&, int volatile &&>, int const volatile &&>::value, "");
static_assert(std::is_same<common_reference_t<int &&, int const &, int volatile &>, int const volatile &>(), "");
// Array types?? Yup!
static_assert(std::is_same<common_reference_t<int (&)[10], int (&&)[10]>, int const(&)[10]>::value, "");
static_assert(std::is_same<common_reference_t<int const (&)[10], int volatile (&)[10]>, int const volatile(&)[10]>::value, "");
static_assert(std::is_same<common_reference_t<int (&)[10], int (&)[11]>, int *>::value, "");
// Some tests for common_pair with common_reference
static_assert(std::is_same<
common_reference_t<std::pair<int &, int &>, common_pair<int,int> const &>,
common_pair<int const &, int const &>
>::value, "");
// BUGBUG TODO Is a workaround possible?
#if !defined(__GNUC__) || __GNUC__ != 4 || __GNUC_MINOR__ > 8
static_assert(std::is_same<
common_reference_t<common_pair<int const &, int const &>, std::pair<int, int>>,
common_pair<int, int>
>::value, "");
static_assert(std::is_same<
::concepts::detail::_builtin_common_t<common_pair<int, int> const &, std::pair<int, int> &>,
std::pair<int, int> const &
>::value, "");
#endif
static_assert(std::is_same<
common_reference_t<common_pair<int, int> const &, std::pair<int, int> &>,
std::pair<int, int> const &
>::value, "");
// Some tests with noncopyable types
static_assert(std::is_same<
::concepts::detail::_builtin_common_t<noncopyable const &, noncopyable>,
noncopyable
>::value, "");
static_assert(std::is_same<
::concepts::detail::_builtin_common_t<noncopyable2 const &, noncopyable>,
noncopyable
>::value, "");
static_assert(std::is_same<
::concepts::detail::_builtin_common_t<noncopyable const &, noncopyable2>,
noncopyable
>::value, "");
static_assert(std::is_same<
common_reference_t<X &, Y const &>,
Z
>::value, "");
{
// Regression test for #367
using CP = common_pair<int, int>;
CPP_assert(same_as<common_type_t<CP, CP>, CP>);
}
}
|
0 | repos/range-v3/test | repos/range-v3/test/utility/CMakeLists.txt | set(CMAKE_FOLDER "${CMAKE_FOLDER}/utility")
rv3_add_test(test.utility.box utility.box box.cpp)
rv3_add_test(test.utility.concepts utility.concepts concepts.cpp)
rv3_add_test(test.utility.common_type utility.common_type common_type.cpp)
rv3_add_test(test.utility.compare utility.compare compare.cpp)
rv3_add_test(test.utility.functional utility.functional functional.cpp)
rv3_add_test(test.utility.swap utility.swap swap.cpp)
rv3_add_test(test.utility.variant utility.variant variant.cpp)
rv3_add_test(test.utility.meta utility.meta meta.cpp)
rv3_add_test(test.utility.scope_exit utility.scope_exit scope_exit.cpp)
rv3_add_test(test.utility.semiregular_box utility.semiregular_box semiregular_box.cpp)
|
0 | repos/range-v3/test | repos/range-v3/test/utility/scope_exit.cpp | // Range v3 library
//
// Copyright Eric Niebler 2017-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <range/v3/utility/scope_exit.hpp>
#include "../simple_test.hpp"
#include "../test_utils.hpp"
RANGES_DIAGNOSTIC_IGNORE_UNNEEDED_MEMBER
namespace
{
int i = 0;
struct NoexceptFalse
{
NoexceptFalse() {}
NoexceptFalse(NoexceptFalse const &) noexcept(false)
{}
NoexceptFalse(NoexceptFalse &&) noexcept(false)
{
CHECK(false);
}
void operator()() const
{
++i;
}
};
struct ThrowingCopy
{
ThrowingCopy() {}
[[noreturn]] ThrowingCopy(ThrowingCopy const &) noexcept(false)
{
throw 42;
}
ThrowingCopy(ThrowingCopy &&) noexcept(false)
{
CHECK(false);
}
void operator()() const
{
++i;
}
};
}
int main()
{
std::cout << "\nTesting scope_exit\n";
{
auto guard = ranges::make_scope_exit([&]{++i;});
CHECK(i == 0);
}
CHECK(i == 1);
{
auto guard = ranges::make_scope_exit(NoexceptFalse{});
CHECK(i == 1);
}
CHECK(i == 2);
try
{
auto guard = ranges::make_scope_exit(ThrowingCopy{});
CHECK(false);
}
catch(int)
{}
CHECK(i == 3);
return ::test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/utility/concepts.cpp | // Range v3 library
//
// Copyright Eric Niebler 2014-present
// Copyright Google LLC 2020-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
//#define RANGES_USE_LEGACY_CONCEPTS 1
#include <sstream>
#include <vector>
#include <concepts/concepts.hpp>
#include <range/v3/iterator/concepts.hpp>
#include <range/v3/iterator/traits.hpp>
#include <range/v3/range/concepts.hpp>
#include <range/v3/range/traits.hpp>
#include <range/v3/view/istream.hpp>
#include <range/v3/iterator/common_iterator.hpp>
#include "../simple_test.hpp"
struct moveonly
{
moveonly(moveonly&&) = default;
moveonly& operator=(moveonly&&) = default;
};
struct nonmovable
{
nonmovable(nonmovable const &) = delete;
nonmovable& operator=(nonmovable const &) = delete;
};
struct nondefaultconstructible
{
nondefaultconstructible(int) {}
};
struct NotDestructible
{
~NotDestructible() = delete;
};
struct IntComparable
{
operator int() const;
friend bool operator==(IntComparable, IntComparable);
friend bool operator!=(IntComparable, IntComparable);
friend bool operator<(IntComparable, IntComparable);
friend bool operator>(IntComparable, IntComparable);
friend bool operator<=(IntComparable, IntComparable);
friend bool operator>=(IntComparable, IntComparable);
friend bool operator==(int, IntComparable);
friend bool operator!=(int, IntComparable);
friend bool operator==(IntComparable, int);
friend bool operator!=(IntComparable, int);
friend bool operator<(int, IntComparable);
friend bool operator<(IntComparable, int);
friend bool operator>(int, IntComparable);
friend bool operator>(IntComparable, int);
friend bool operator<=(int, IntComparable);
friend bool operator<=(IntComparable, int);
friend bool operator>=(int, IntComparable);
friend bool operator>=(IntComparable, int);
};
struct IntSwappable
{
operator int() const;
friend void swap(int &, IntSwappable);
friend void swap(IntSwappable, int &);
friend void swap(IntSwappable, IntSwappable);
};
static_assert(ranges::same_as<int, int>, "");
static_assert(ranges::same_as<void, void>, "");
static_assert(ranges::same_as<void const, void const>, "");
static_assert(!ranges::same_as<int&, int>, "");
static_assert(!ranges::same_as<void, void const>, "");
static_assert(!ranges::same_as<void(), void(*)()>, "");
static_assert(ranges::convertible_to<int, int>, "");
static_assert(ranges::convertible_to<short&, short const&>, "");
static_assert(ranges::convertible_to<int, short>, "");
static_assert(!ranges::convertible_to<int&, short&>, "");
static_assert(!ranges::convertible_to<int, void>, "");
static_assert(!ranges::convertible_to<int, int&>, "");
static_assert(ranges::unsigned_integral<unsigned>, "");
static_assert(!ranges::unsigned_integral<int>, "");
static_assert(ranges::assignable_from<int&, int>, "");
static_assert(!ranges::assignable_from<int const&, int>, "");
static_assert(!ranges::assignable_from<int, int>, "");
static_assert(ranges::destructible<int>, "");
static_assert(ranges::destructible<const int>, "");
static_assert(!ranges::destructible<void>, "");
static_assert(ranges::destructible<int&>, "");
static_assert(!ranges::destructible<void()>, "");
static_assert(ranges::destructible<void(*)()>, "");
static_assert(ranges::destructible<void(&)()>, "");
static_assert(!ranges::destructible<int[]>, "");
static_assert(ranges::destructible<int[2]>, "");
static_assert(ranges::destructible<int(*)[2]>, "");
static_assert(ranges::destructible<int(&)[2]>, "");
static_assert(ranges::destructible<moveonly>, "");
static_assert(ranges::destructible<nonmovable>, "");
static_assert(!ranges::destructible<NotDestructible>, "");
static_assert(ranges::constructible_from<int>, "");
static_assert(ranges::constructible_from<int const>, "");
static_assert(!ranges::constructible_from<void>, "");
static_assert(!ranges::constructible_from<int const &>, "");
static_assert(!ranges::constructible_from<int ()>, "");
static_assert(!ranges::constructible_from<int(&)()>, "");
static_assert(!ranges::constructible_from<int[]>, "");
static_assert(ranges::constructible_from<int[5]>, "");
static_assert(!ranges::constructible_from<nondefaultconstructible>, "");
static_assert(ranges::constructible_from<int const(&)[5], int(&)[5]>, "");
static_assert(!ranges::constructible_from<int, int(&)[3]>, "");
static_assert(ranges::constructible_from<int, int>, "");
static_assert(ranges::constructible_from<int, int&>, "");
static_assert(ranges::constructible_from<int, int&&>, "");
static_assert(ranges::constructible_from<int, const int>, "");
static_assert(ranges::constructible_from<int, const int&>, "");
static_assert(ranges::constructible_from<int, const int&&>, "");
static_assert(!ranges::constructible_from<int&, int>, "");
static_assert(ranges::constructible_from<int&, int&>, "");
static_assert(!ranges::constructible_from<int&, int&&>, "");
static_assert(!ranges::constructible_from<int&, const int>, "");
static_assert(!ranges::constructible_from<int&, const int&>, "");
static_assert(!ranges::constructible_from<int&, const int&&>, "");
static_assert(ranges::constructible_from<const int&, int>, "");
static_assert(ranges::constructible_from<const int&, int&>, "");
static_assert(ranges::constructible_from<const int&, int&&>, "");
static_assert(ranges::constructible_from<const int&, const int>, "");
static_assert(ranges::constructible_from<const int&, const int&>, "");
static_assert(ranges::constructible_from<const int&, const int&&>, "");
static_assert(ranges::constructible_from<int&&, int>, "");
static_assert(!ranges::constructible_from<int&&, int&>, "");
static_assert(ranges::constructible_from<int&&, int&&>, "");
static_assert(!ranges::constructible_from<int&&, const int>, "");
static_assert(!ranges::constructible_from<int&&, const int&>, "");
static_assert(!ranges::constructible_from<int&&, const int&&>, "");
static_assert(ranges::constructible_from<const int&&, int>, "");
static_assert(!ranges::constructible_from<const int&&, int&>, "");
static_assert(ranges::constructible_from<const int&&, int&&>, "");
static_assert(ranges::constructible_from<const int&&, const int>, "");
static_assert(!ranges::constructible_from<const int&&, const int&>, "");
static_assert(ranges::constructible_from<const int&&, const int&&>, "");
struct XXX
{
XXX() = default;
XXX(XXX&&) = delete;
explicit XXX(int) {}
};
static_assert(ranges::constructible_from<XXX, int>, "");
static_assert(!ranges::move_constructible<XXX>, "");
static_assert(!ranges::movable<XXX>, "");
static_assert(!ranges::semiregular<XXX>, "");
static_assert(!ranges::regular<XXX>, "");
static_assert(ranges::default_constructible<int>, "");
static_assert(ranges::default_constructible<int const>, "");
static_assert(!ranges::default_constructible<int const &>, "");
static_assert(!ranges::default_constructible<int ()>, "");
static_assert(!ranges::default_constructible<int(&)()>, "");
static_assert(!ranges::default_constructible<int[]>, "");
static_assert(ranges::default_constructible<int[5]>, "");
static_assert(!ranges::default_constructible<nondefaultconstructible>, "");
static_assert(ranges::move_constructible<int>, "");
static_assert(ranges::move_constructible<const int>, "");
static_assert(ranges::move_constructible<int &>, "");
static_assert(ranges::move_constructible<int &&>, "");
static_assert(ranges::move_constructible<const int &>, "");
static_assert(ranges::move_constructible<const int &&>, "");
static_assert(ranges::destructible<moveonly>, "");
static_assert(ranges::constructible_from<moveonly, moveonly>, "");
static_assert(ranges::move_constructible<moveonly>, "");
static_assert(!ranges::move_constructible<nonmovable>, "");
static_assert(ranges::move_constructible<nonmovable &>, "");
static_assert(ranges::move_constructible<nonmovable &&>, "");
static_assert(ranges::move_constructible<const nonmovable &>, "");
static_assert(ranges::move_constructible<const nonmovable &&>, "");
static_assert(ranges::copy_constructible<int>, "");
static_assert(ranges::copy_constructible<const int>, "");
static_assert(ranges::copy_constructible<int &>, "");
static_assert(!ranges::copy_constructible<int &&>, "");
static_assert(ranges::copy_constructible<const int &>, "");
static_assert(!ranges::copy_constructible<const int &&>, "");
static_assert(!ranges::copy_constructible<moveonly>, "");
static_assert(!ranges::copy_constructible<nonmovable>, "");
static_assert(ranges::copy_constructible<nonmovable &>, "");
static_assert(!ranges::copy_constructible<nonmovable &&>, "");
static_assert(ranges::copy_constructible<const nonmovable &>, "");
static_assert(!ranges::copy_constructible<const nonmovable &&>, "");
static_assert(ranges::movable<int>, "");
static_assert(!ranges::movable<int const>, "");
static_assert(ranges::movable<moveonly>, "");
static_assert(!ranges::movable<nonmovable>, "");
static_assert(ranges::copyable<int>, "");
static_assert(!ranges::copyable<int const>, "");
static_assert(!ranges::copyable<moveonly>, "");
static_assert(!ranges::copyable<nonmovable>, "");
// static_assert(ranges::predicate<std::less<int>, int, int>, "");
// static_assert(!ranges::predicate<std::less<int>, char*, int>, "");
static_assert(ranges::input_iterator<int*>, "");
static_assert(!ranges::input_iterator<int>, "");
static_assert(ranges::forward_iterator<int*>, "");
static_assert(!ranges::forward_iterator<int>, "");
static_assert(ranges::bidirectional_iterator<int*>, "");
static_assert(!ranges::bidirectional_iterator<int>, "");
static_assert(ranges::random_access_iterator<int*>, "");
static_assert(!ranges::random_access_iterator<int>, "");
static_assert(ranges::contiguous_iterator<int*>, "");
static_assert(!ranges::contiguous_iterator<int>, "");
static_assert(ranges::view_<ranges::istream_view<int>>, "");
static_assert(ranges::input_iterator<ranges::iterator_t<ranges::istream_view<int>>>, "");
static_assert(!ranges::view_<int>, "");
static_assert(ranges::common_range<std::vector<int> >, "");
static_assert(ranges::common_range<std::vector<int> &>, "");
static_assert(!ranges::view_<std::vector<int>>, "");
static_assert(!ranges::view_<std::vector<int> &>, "");
static_assert(ranges::random_access_iterator<ranges::iterator_t<std::vector<int> const &>>, "");
static_assert(!ranges::common_range<ranges::istream_view<int>>, "");
static_assert(ranges::predicate<std::less<int>, int, int>, "");
static_assert(!ranges::predicate<std::less<int>, char*, int>, "");
static_assert(ranges::output_iterator<int *, int>, "");
static_assert(!ranges::output_iterator<int const *, int>, "");
static_assert(ranges::swappable<int &>, "");
static_assert(ranges::swappable<int>, "");
static_assert(!ranges::swappable<int const &>, "");
static_assert(ranges::swappable<IntSwappable>, "");
static_assert(ranges::swappable_with<IntSwappable, int &>, "");
static_assert(!ranges::swappable_with<IntSwappable, int const &>, "");
static_assert(ranges::totally_ordered<int>, "");
static_assert(ranges::common_with<int, IntComparable>, "");
static_assert(ranges::common_reference_with<int &, IntComparable &>, "");
static_assert(ranges::totally_ordered_with<int, IntComparable>, "");
static_assert(ranges::totally_ordered_with<IntComparable, int>, "");
static_assert(ranges::detail::weakly_equality_comparable_with_<int, int>, "");
static_assert(ranges::equality_comparable<int>, "");
static_assert(ranges::equality_comparable_with<int, int>, "");
static_assert(ranges::equality_comparable_with<int, IntComparable>, "");
static_assert(ranges::equality_comparable_with<int &, IntComparable &>, "");
#if __cplusplus > 201703L && __has_include(<compare>) && \
defined(__cpp_concepts) && defined(__cpp_impl_three_way_comparison)
#include <compare>
static_assert(ranges::three_way_comparable<int>);
static_assert(ranges::three_way_comparable<int, std::partial_ordering>);
static_assert(ranges::three_way_comparable<int, std::weak_ordering>);
static_assert(ranges::three_way_comparable<int, std::strong_ordering>);
static_assert(ranges::three_way_comparable_with<int, IntComparable>);
static_assert(ranges::three_way_comparable_with<int, IntComparable, std::partial_ordering>);
static_assert(ranges::three_way_comparable_with<int, IntComparable, std::weak_ordering>);
static_assert(ranges::three_way_comparable_with<int, IntComparable, std::strong_ordering>);
static_assert(ranges::three_way_comparable_with<IntComparable, int>);
static_assert(ranges::three_way_comparable_with<IntComparable, int, std::partial_ordering>);
static_assert(ranges::three_way_comparable_with<IntComparable, int, std::weak_ordering>);
static_assert(ranges::three_way_comparable_with<IntComparable, int, std::strong_ordering>);
#endif // supports spaceship
static_assert(
std::is_same<
ranges::common_range_tag_of<std::vector<int>>,
ranges::common_range_tag
>::value, "");
static_assert(
std::is_same<
ranges::sized_range_tag_of<std::vector<int>>,
ranges::sized_range_tag
>::value, "");
static_assert(ranges::view_<ranges::istream_view<int>>, "");
static_assert(!ranges::common_range<ranges::istream_view<int>>, "");
static_assert(!ranges::sized_range<ranges::istream_view<int>>, "");
struct myview : ranges::view_base {
const char *begin();
const char *end();
};
CPP_assert(ranges::view_<myview>);
CPP_template(class T)
(requires ranges::regular<T>)
constexpr bool is_regular(T&&)
{
return true;
}
CPP_template(class T)
(requires (!ranges::regular<T>))
constexpr bool is_regular(T&&)
{
return false;
}
static_assert(is_regular(42), "");
static_assert(!is_regular(XXX{}), "");
int main()
{
return test_result();
}
|
0 | repos/range-v3/test | repos/range-v3/test/utility/semiregular_box.cpp | // Range v3 library
//
// Copyright Eric Niebler 2020-present
//
// Use, modification and distribution is subject to the
// Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// Project home: https://github.com/ericniebler/range-v3
#include <range/v3/utility/semiregular_box.hpp>
#include "../simple_test.hpp"
using namespace ranges;
// #https://github.com/ericniebler/range-v3/issues/1499
void test_1499()
{
ranges::semiregular_box_t<int> box1;
ranges::semiregular_box_t<int &> box2;
detail::ignore_unused(
box1, //
box2); //
}
int main()
{
test_1499();
return ::test_result();
}
|
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.