Skip to content

Commit

Permalink
Export of internal changes
Browse files Browse the repository at this point in the history
  • Loading branch information
foonathan committed Apr 25, 2024
1 parent b9c84dd commit 199d817
Show file tree
Hide file tree
Showing 388 changed files with 37,800 additions and 4,598 deletions.
2 changes: 1 addition & 1 deletion tc/algorithm/accumulate.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

// think-cell public library
//
// Copyright (C) 2016-2023 think-cell Software GmbH
// Copyright (C) think-cell Software GmbH
//
// Distributed under 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
Expand Down
375 changes: 203 additions & 172 deletions tc/algorithm/algorithm.h

Large diffs are not rendered by default.

30 changes: 21 additions & 9 deletions tc/algorithm/algorithm.t.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

// think-cell public library
//
// Copyright (C) 2016-2023 think-cell Software GmbH
// Copyright (C) think-cell Software GmbH
//
// Distributed under 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
Expand Down Expand Up @@ -75,10 +75,22 @@ UNITTESTDEF(filter_no_self_assignment_of_rvalues) {

UNITTESTDEF( trim_leftright_if ) {
tc::vector<int> v{1,2,3,4,5,6,7,7,7};
auto rng = tc::trim_left_if<tc::return_drop>(v, [] (int const n) noexcept {return n<4;});
_ASSERT(tc::begin(rng) != tc::end(rng));
_ASSERTEQUAL(tc::size(rng), 6);
_ASSERTEQUAL(tc::size(tc::trim_right_if<tc::return_take>(rng, [] (int const n) noexcept {return n==7;})), 3);

decltype(auto) left = tc::trim_left_if<tc::return_drop>(v, [] (int const n) noexcept {return n<4;});
STATICASSERTSAME(decltype(left), tc::iterator_range_t<tc::vector<int>&>);
TEST_RANGE_EQUAL(left, (tc::literal_range_of<4, 5, 6, 7, 7, 7>));

decltype(auto) left_then_right = tc::trim_right_if<tc::return_take>(tc_move(left), [] (int const n) noexcept {return n==7;});
STATICASSERTSAME(decltype(left_then_right), tc::iterator_range_t<tc::vector<int>&>&&);
TEST_RANGE_EQUAL(left_then_right, (tc::literal_range_of<4, 5, 6>));

decltype(auto) both = tc::trim_if(v, [](int const n) { return n < 4 || n == 7; });
STATICASSERTSAME(decltype(both), tc::iterator_range_t<tc::vector<int>&>);
TEST_RANGE_EQUAL(both, (tc::literal_range_of<4, 5, 6>));

decltype(auto) both_prvalue = tc::trim_if(tc::decay_copy(v), [](int const n) { return n < 4 || n == 7; });
STATICASSERTSAME(decltype(both_prvalue), tc::slice_t<tc::vector<int>>);
TEST_RANGE_EQUAL(both_prvalue, (tc::literal_range_of<4, 5, 6>));
}

UNITTESTDEF( is_sorted ) {
Expand Down Expand Up @@ -151,7 +163,7 @@ UNITTESTDEF(Naryinterleave) {
tc::interleave_n(
tc::fn_compare(),
[&](auto const&... pairitb) noexcept {
auto tplpairitb = std::make_tuple(pairitb...);
auto tplpairitb = tc::tie(pairitb...);
if (tc::get<0>(tplpairitb).second) {
_ASSERTEQUAL(*itResult,*tc::get<0>(tplpairitb).first);
++itResult;
Expand Down Expand Up @@ -191,7 +203,7 @@ UNITTESTDEF(NaryinterleaveBreak) {
tc::interleave_n(
tc::fn_compare(),
[&](auto const&... pairitb) noexcept {
auto tplpairitb = std::make_tuple(pairitb...);
auto tplpairitb = tc::tie(pairitb...);
if (tc::get<0>(tplpairitb).second) {
_ASSERTEQUAL(*itResult, *tc::get<0>(tplpairitb).first);
++itResult;
Expand Down Expand Up @@ -301,13 +313,13 @@ UNITTESTDEF(constexpr_sort_test) {
std::mt19937 gen; // same sequence of numbers each time for reproducibility
std::uniform_int_distribution<> dist(0, 63);

static auto constexpr Test = [](auto rngn) noexcept {
tc_static_auto_constexpr_lambda(Test) = [](auto rngn) noexcept {
auto vecn = tc::explicit_cast<tc::vector<int>>(rngn);
_ASSERTEQUAL(tc_modified(vecn, tc::sort_inplace(_)), tc_modified(vecn, tc::constexpr_sort_inplace_detail::constexpr_sort_inplace(tc::begin(_), tc::end(_), tc::fn_less())));
};

for( int i = 0; i < 17; ++i ) {
Test(tc::begin_next<tc::return_take>([&](auto sink) noexcept { for(;;) tc_yield(sink, dist(gen)); }, dist(gen)));
Test(tc::begin_next<tc::return_take>([&](auto sink) noexcept { for(;;) tc_return_if_break(tc::continue_if_not_break(sink, dist(gen))); }, dist(gen)));
Test(tc::iota(0, i));
Test(tc::reverse(tc::iota(0, i)));
Test(tc::repeat_n(i, 0));
Expand Down
2 changes: 1 addition & 1 deletion tc/algorithm/any_accu.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

// think-cell public library
//
// Copyright (C) 2016-2023 think-cell Software GmbH
// Copyright (C) think-cell Software GmbH
//
// Distributed under 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
Expand Down
38 changes: 34 additions & 4 deletions tc/algorithm/append.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

// think-cell public library
//
// Copyright (C) 2016-2023 think-cell Software GmbH
// Copyright (C) think-cell Software GmbH
//
// Distributed under 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
Expand All @@ -21,8 +21,11 @@

#include "../range/subrange.h"
#include "../range/transform.h"
#include "../range/repeat_n.h"
#include "../range/concat_adaptor.h"

#include <boost/range/algorithm/copy.hpp>

namespace tc {
namespace append_detail {
template<typename Rng, typename TTarget>
Expand All @@ -38,12 +41,12 @@ namespace tc {
concept range_insertable =
(!conv_enc_needed<Rng, tc::range_value_t<Cont>>) &&
has_mem_fn_reserve<Cont> &&
!tc::is_concat_range<std::remove_cvref_t<Rng>>::value && // it might be more efficient to append by ranges than by iterators
tc::common_range<Rng> &&
std::convertible_to<
typename std::iterator_traits<tc::iterator_t<Rng>>::iterator_category,
std::random_access_iterator_tag
> &&
(!tc::prefers_for_each<Rng>) && // it might be more efficient to append by ranges than by iterators
tc::econstructionIMPLICIT==tc::construction_restrictiveness<tc::range_value_t<Cont>, std::iter_reference_t<tc::iterator_t<Rng>>>::value;
}

Expand Down Expand Up @@ -77,6 +80,33 @@ namespace tc {
void chunk(append_detail::conv_enc_needed<tc::range_value_t<Cont>> auto&& rng) const& return_MAYTHROW(
tc::implicit_cast<void>(tc::for_each(tc::convert_enc<tc::range_value_t<Cont>>(tc_move_if_owned(rng)), *this))
)

template<ENABLE_SFINAE> requires std::is_same<tc::range_value_t<SFINAE_TYPE(Cont)&>, unsigned char>::value
auto write_offset(std::size_t n) const& noexcept {
struct stream_pos_writer final {
Cont& m_cont;
decltype(tc::size_raw(m_cont)) m_pos;

explicit stream_pos_writer(Cont& cont) noexcept
: m_cont(cont)
, m_pos(tc::size_raw(m_cont))
{}

void mark() & noexcept {
// The offset is counted from _after_ the written offset.
boost::copy(tc::as_blob(tc::explicit_cast<std::uint32_t>(tc::size_raw(m_cont)-m_pos-sizeof(std::uint32_t))), tc::begin_next(m_cont, m_pos));
m_pos+=sizeof(std::uint32_t);
}

void mark_null() & noexcept {
boost::copy(tc::as_blob(std::numeric_limits<std::uint32_t>::max()), tc::begin_next(m_cont, m_pos));
m_pos+=sizeof(std::uint32_t);
}
};
stream_pos_writer ow(m_cont);
tc::for_each(tc::repeat_n(sizeof(std::uint32_t)*n, tc::explicit_cast<unsigned char>(0)), *this);
return ow;
}
};

template< typename Cont >
Expand Down Expand Up @@ -211,7 +241,7 @@ namespace tc {

template<appendable_container TTarget, typename Rng0, tc::appendable<TTarget&>... RngN>
requires explicit_convert_to_container_detail::use_ctor<TTarget, Rng0, RngN...>::value
constexpr TTarget explicit_convert_impl(adl_tag_t, tc::type::identity<TTarget>, Rng0&& rng0, RngN&&... rngN) MAYTHROW {
constexpr TTarget explicit_convert_impl(adl_tag_t, std::type_identity<TTarget>, Rng0&& rng0, RngN&&... rngN) MAYTHROW {
if constexpr(0<sizeof...(RngN)) {
TTarget cont=tc_move_if_owned(rng0);
tc::append(cont, tc_move_if_owned(rngN)...);
Expand All @@ -223,7 +253,7 @@ namespace tc {

template<appendable_container TTarget, tc::appendable<TTarget&> Rng0, tc::appendable<TTarget&>... RngN>
requires (!explicit_convert_to_container_detail::use_ctor<TTarget, Rng0, RngN...>::value)
constexpr TTarget explicit_convert_impl(adl_tag_t, tc::type::identity<TTarget>, Rng0&& rng0, RngN&&... rngN) MAYTHROW {
constexpr TTarget explicit_convert_impl(adl_tag_t, std::type_identity<TTarget>, Rng0&& rng0, RngN&&... rngN) MAYTHROW {
TTarget cont;
tc::append(cont, tc_move_if_owned(rng0), tc_move_if_owned(rngN)...);
return cont;
Expand Down
2 changes: 1 addition & 1 deletion tc/algorithm/append.t.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

// think-cell public library
//
// Copyright (C) 2016-2023 think-cell Software GmbH
// Copyright (C) think-cell Software GmbH
//
// Distributed under 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
Expand Down
6 changes: 3 additions & 3 deletions tc/algorithm/best_element.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

// think-cell public library
//
// Copyright (C) 2016-2023 think-cell Software GmbH
// Copyright (C) think-cell Software GmbH
//
// Distributed under 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
Expand All @@ -10,7 +10,7 @@

#include "../range/subrange.h"
#include "../storage_for.h"
#include "../base/assign.h"
#include "../base/change.h"
#include "accumulate.h"
#include "compare.h"

Expand Down Expand Up @@ -39,7 +39,7 @@ namespace tc {
}
aoref[1-i].ctor( aggregate_tag, *ait[1-i] ); // MAYTHROW
try {
if( tc::invoke(better, tc::as_const(**aoref[1-i]), tc::as_const(**aoref[i])) ) { // MAYTHROW
if( tc_invoke(better, tc::as_const(**aoref[1-i]), tc::as_const(**aoref[i])) ) { // MAYTHROW
break; // only path where aoref[1-i] is not destroyed
}
} catch(...) {
Expand Down
31 changes: 22 additions & 9 deletions tc/algorithm/binary_operators.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

// think-cell public library
//
// Copyright (C) 2016-2023 think-cell Software GmbH
// Copyright (C) think-cell Software GmbH
//
// Distributed under 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
Expand All @@ -12,6 +12,10 @@
#include "../base/modified.h"
#include "../base/empty_chain.h"
#include "round.h"
#ifdef MSVC_WORKAROUND
#include <boost/preprocessor/punctuation/comma.hpp>
#include <boost/preprocessor/punctuation/paren.hpp>
#endif

namespace tc {
#pragma push_macro("GENERIC_OP_BODY")
Expand Down Expand Up @@ -43,7 +47,7 @@ namespace tc {
struct name##_conversion_type { \
using type = Lhs; \
}; \
template< typename Lhs, typename Rhs, typename=void > \
template< typename Lhs, typename Rhs> \
struct internal_##name##_conversion_type : name##_conversion_type<Lhs, Rhs> { }; \
} \
namespace generic_operator_helper { \
Expand Down Expand Up @@ -143,7 +147,8 @@ namespace tc {
#pragma push_macro("PROXY_CONVERSION")
#define PROXY_CONVERSION(nameFrom, nameTo) \
template< typename Lhs, typename Rhs > \
struct internal_##nameFrom##_conversion_type<Lhs, Rhs, tc::void_t<typename nameTo##_conversion_type<Lhs, Rhs>::type>> \
requires requires { typename nameTo##_conversion_type<Lhs, Rhs>::type; } \
struct internal_##nameFrom##_conversion_type<Lhs, Rhs> \
: nameTo##_conversion_type<Lhs, Rhs> \
{}

Expand Down Expand Up @@ -179,9 +184,10 @@ namespace tc {
template<typename FnOp, typename Rhs>
struct func {
Rhs const& m_rhs;
template<typename LhsElement>
constexpr auto operator()(LhsElement&& lhselem) const& return_decltype_xvalue_by_ref_MAYTHROW( // should be NOEXCEPT, but NOEXCEPT does not allow xvalues.
FnOp()(tc_move_if_owned(lhselem), m_rhs)

template <typename LhsElement>
constexpr auto operator()(LhsElement&& lhselem) const& return_decltype_allow_xvalue_MAYTHROW( // should be NOEXCEPT, but NOEXCEPT does not allow xvalues.
tc_invoke(FnOp(), tc_move_if_owned(lhselem), m_rhs)
)
};

Expand All @@ -208,9 +214,16 @@ namespace tc {
namespace no_adl { \
template<typename Base = void, std::size_t nTransformDepth = 0, typename PrePostOperation = prepostopdefault> \
struct TC_EMPTY_BASES scalar_ ## name : std::conditional_t<std::is_void<Base>::value, tc::empty_chain<scalar_ ## name<void, nTransformDepth, PrePostOperation>>, Base> { \
template<tc::decayed_derived_from<scalar_ ## name> Lhs, typename Rhs> requires requires { \
std::declval<Lhs>().template transform<nTransformDepth>(std::declval<scalar_binary_op_detail::no_adl::func<fnop, Rhs>>()); \
} \
template<tc::decayed_derived_from<scalar_ ## name> Lhs, typename Rhs \
IF_MSVC_WORKAROUND_ELSE( \
TC_FWD(BOOST_PP_COMMA() typename=decltype BOOST_PP_LPAREN()), /* workaround VS17.8 compiler bug: https://developercommunity.visualstudio.com/t/template-member-function-is-not-recogniz/10504199 */ \
TC_FWD(> requires requires {) \
) \
std::declval<Lhs>().template transform<nTransformDepth>(std::declval<scalar_binary_op_detail::no_adl::func<fnop, Rhs>>())IF_NO_MSVC_WORKAROUND(;) \
IF_MSVC_WORKAROUND_ELSE( \
BOOST_PP_RPAREN()>, \
} \
) \
[[nodiscard]] friend constexpr decltype(auto) operator op(Lhs&& lhs, Rhs const& rhs) noexcept { \
PrePostOperation::pre(rhs); \
decltype(auto) _ = tc_move_if_owned(lhs).template transform<nTransformDepth>(scalar_binary_op_detail::no_adl::func<fnop, Rhs>{rhs}); \
Expand Down
Loading

0 comments on commit 199d817

Please sign in to comment.