Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions include/daw/algorithms/daw_algorithm_accumulate.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ namespace daw::algorithm {

template<typename C>
inline constexpr bool is_container_like_v<
C,
std::void_t<decltype( ( (void)std::declval<C const &>( ).begin( ) ),
( (void)std::declval<C const &>( ).end( ) ) )>> =
C, std::void_t<decltype( ( (void)std::declval<C const &>( ).begin( ) ),
( (void)std::declval<C const &>( ).end( ) ) )>> =
true;

struct plus {
Expand All @@ -34,8 +33,8 @@ namespace daw::algorithm {
};
} // namespace accum_impl
template<typename InputIterator, typename T>
constexpr auto
accumulate( InputIterator first, InputIterator last, T init ) noexcept {
constexpr auto accumulate( InputIterator first, InputIterator last,
T init ) noexcept {
DAW_UNSAFE_BUFFER_FUNC_START
for( ; first != last; ++first ) {
init = std::move( init ) + *first;
Expand All @@ -57,16 +56,12 @@ namespace daw::algorithm {
* @param binary_op operation to run
* @return sum of values
*/
template<typename InputIterator,
typename LastType,
typename T,
template<typename InputIterator, typename LastType, typename T,
typename BinaryOperation = accum_impl::plus,
std::enable_if_t<not accum_impl::is_container_like_v<InputIterator>,
std::nullptr_t> = nullptr>
constexpr auto accumulate(
InputIterator first,
LastType last,
T init,
InputIterator first, LastType last, T init,
BinaryOperation binary_op =
BinaryOperation{ } ) noexcept( noexcept( binary_op( std::move( init ),
*first ) ) ) {
Expand Down
3 changes: 1 addition & 2 deletions include/daw/algorithms/daw_algorithm_copy.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ namespace daw::algorithm {
/// @return end of output range written to
template<typename InputIterator, typename LastType, typename OutputIterator>
constexpr OutputIterator
copy( InputIterator first,
LastType last,
copy( InputIterator first, LastType last,
OutputIterator first_out ) noexcept( noexcept( *first_out = *first ) ) {

traits::is_input_iterator_test<InputIterator>( );
Expand Down
3 changes: 1 addition & 2 deletions include/daw/algorithms/daw_algorithm_copy_n.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ namespace daw::algorithm {
/// @return end of output range written to
template<typename InputIterator, typename OutputIterator>
constexpr auto
copy_n( InputIterator first,
OutputIterator first_out,
copy_n( InputIterator first, OutputIterator first_out,
size_t count ) noexcept( noexcept( *first_out = *first ) ) {

traits::is_input_iterator_test<InputIterator>( );
Expand Down
13 changes: 5 additions & 8 deletions include/daw/algorithms/daw_algorithm_find.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ namespace daw::algorithm {
}

template<typename InputIterator, typename ForwardIterator>
[[nodiscard]] constexpr InputIterator find_first_of( InputIterator first,
InputIterator last,
ForwardIterator sfirst,
ForwardIterator slast ) {
[[nodiscard]] constexpr InputIterator
find_first_of( InputIterator first, InputIterator last,
ForwardIterator sfirst, ForwardIterator slast ) {

(void)daw::traits::is_input_iterator_test<InputIterator>( );
(void)daw::traits::is_forward_access_iterator_test<ForwardIterator>( );
Expand All @@ -50,11 +49,9 @@ namespace daw::algorithm {
return last;
}

template<typename InputIterator,
typename InputIteratorLast,
template<typename InputIterator, typename InputIteratorLast,
typename UnaryPredicate>
constexpr InputIterator find_if( InputIterator first,
InputIteratorLast last,
constexpr InputIterator find_if( InputIterator first, InputIteratorLast last,
UnaryPredicate &&unary_predicate ) {
daw::traits::is_input_iterator_test<InputIterator>( );
daw::traits::is_unary_predicate_test<UnaryPredicate, decltype( *first )>( );
Expand Down
11 changes: 4 additions & 7 deletions include/daw/algorithms/daw_algorithm_find_transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ namespace daw::algorithm {
/// It minimizes the cost when the transformation is expensive and
/// only calls it once per element until the predicate returns true
/// on the transformed result
template<typename Iterator,
typename IteratorLast,
typename Func,
template<typename Iterator, typename IteratorLast, typename Func,
typename Pred>
constexpr find_transform_result_t<Iterator> find_transform( Iterator first,
IteratorLast last,
Func &&func,
Pred &&pred ) {
constexpr find_transform_result_t<Iterator>
find_transform( Iterator first, IteratorLast last, Func &&func,
Pred &&pred ) {
while( first != last ) {
auto result = func( *first );
if( pred( result ) ) {
Expand Down
6 changes: 2 additions & 4 deletions include/daw/algorithms/daw_algorithm_partial_sum.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
#include <daw/stdinc/move_fwd_exch.h>

namespace daw::algorithm {
template<typename InputIterator,
typename OutputIterator,
template<typename InputIterator, typename OutputIterator,
typename BinaryOperator = accum_impl::plus>
constexpr OutputIterator
partial_sum( InputIterator first,
InputIterator last,
partial_sum( InputIterator first, InputIterator last,
OutputIterator first_out,
BinaryOperator op = BinaryOperator{ } ) {

Expand Down
6 changes: 3 additions & 3 deletions include/daw/algorithms/daw_array_compare.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ namespace daw {
remove_array_ref_t<T>>>
DAW_ATTRIB_FLATTEN constexpr auto
array_cmp( T &&lhs, T &&rhs, Compare const &cmp = Compare{ } ) {
using compare_result_t =
std::invoke_result_t<Compare, std::remove_all_extents_t<U>,
std::remove_all_extents_t<U>>;
using compare_result_t = std::invoke_result_t<Compare,
std::remove_all_extents_t<U>,
std::remove_all_extents_t<U>>;
for( std::size_t n = 0; n < std::extent_v<U>; ++n ) {
auto r = [&] {
if constexpr( std::rank_v<U> > 1 ) {
Expand Down
62 changes: 30 additions & 32 deletions include/daw/algorithms/daw_enumerate_tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

#pragma once

#include "daw/cpp_17.h"
#include "daw/daw_concepts.h"
#include "daw/daw_constant.h"
#include "daw_enumerate_tuple.h"
#include "daw/cpp_17.h"
#include "daw/daw_move.h"
#include "daw_enumerate_tuple.h"

#include <cstddef>
#include <utility>
Expand All @@ -29,9 +29,10 @@ namespace daw {
value_t value;

template<IntegralStd auto I, typename Self>
requires ( I >= 0 and I < 2 )
constexpr decltype(auto) operator[]( this Self &&self, daw::constant<I> ) {
if constexpr(I == 0) {
requires( I >= 0 and I < 2 )
constexpr decltype( auto ) operator[]( this Self &&self,
daw::constant<I> ) {
if constexpr( I == 0 ) {
return Self::index;
} else {
return std::forward_like<Self>( self.value );
Expand All @@ -40,27 +41,24 @@ namespace daw {
};

template<typename T>
concept EnumeratedTuple = requires
{
typename std::remove_cvref_t<T>::i_am_an_enumerated_tuple;
};
concept EnumeratedTuple =
requires { typename std::remove_cvref_t<T>::i_am_an_enumerated_tuple; };

template<typename T>
concept EnumeratedTupleElement = requires
{
concept EnumeratedTupleElement = requires {
typename std::remove_cvref_t<T>::i_am_an_enumerated_tuple_element;
};

template<EnumeratedTuple T>
using enumerated_tuple_index_t = typename std::remove_cvref_t<T>::index_t;

template<EnumeratedTupleElement T>
using enumerated_tuple_element_index_t = typename std::remove_cvref_t<
T>::index_t;
using enumerated_tuple_element_index_t =
typename std::remove_cvref_t<T>::index_t;

template<EnumeratedTupleElement T>
using enumerated_tuple_element_value_t = typename std::remove_cvref_t<
T>::value_t;
using enumerated_tuple_element_value_t =
typename std::remove_cvref_t<T>::value_t;

template<typename Tp, typename Index = std::size_t>
struct enumerated_tuple_t {
Expand All @@ -71,24 +69,24 @@ namespace daw {

template<auto Idx, typename Self>
constexpr auto operator[]( this Self &&self, daw::constant<Idx> ) {
static constexpr auto i = static_cast<std::size_t>(Idx);
using element_t = decltype( std::get<i>(
std::forward_like<Self>( self.m_tuple ) ) );
return enumerate_tuple_element_t<element_t, static_cast<index_t>(Idx)>{
std::get<i>( std::forward_like<Self>( self.m_tuple ) )};
static constexpr auto i = static_cast<std::size_t>( Idx );
using element_t =
decltype( std::get<i>( std::forward_like<Self>( self.m_tuple ) ) );
return enumerate_tuple_element_t<element_t, static_cast<index_t>( Idx )>{
std::get<i>( std::forward_like<Self>( self.m_tuple ) ) };
}
};

template<typename Index = std::size_t, typename Tp>
constexpr enumerated_tuple_t<Tp, Index> enumerate_tuple( Tp &&tp ) {
return {DAW_FWD( tp )};
return { DAW_FWD( tp ) };
}
}
} // namespace daw

namespace std {
template<daw::EnumeratedTuple ET>
inline constexpr std::size_t tuple_size_v<ET> = std::tuple_size_v<typename
std::remove_cvref_t<ET>::tuple_t>;
inline constexpr std::size_t tuple_size_v<ET> =
std::tuple_size_v<typename std::remove_cvref_t<ET>::tuple_t>;

template<daw::EnumeratedTuple ET>
struct tuple_size<ET> {
Expand All @@ -106,39 +104,39 @@ namespace std {
template<std::size_t I, daw::EnumeratedTuple ET>
struct tuple_element<I, ET> {
using index_t = daw::enumerated_tuple_index_t<ET>;
static constexpr index_t index = static_cast<index_t>(I);
static constexpr index_t index = static_cast<index_t>( I );
using type_t = std::tuple_element_t<I, std::remove_cvref_t<ET>>;
using type = daw::enumerate_tuple_element_t<type_t, index>;
};

template<std::size_t Idx, daw::EnumeratedTupleElement ETE>
requires( Idx == 0 )
requires( Idx == 0 )
struct tuple_element<Idx, ETE> {
using type = daw::enumerated_tuple_element_index_t<ETE>;
};

template<std::size_t Idx, daw::EnumeratedTupleElement ETE>
requires( Idx == 1 )
requires( Idx == 1 )
struct tuple_element<Idx, ETE> {
using type = daw::enumerated_tuple_element_value_t<ETE>;
};

template<std::size_t Idx, daw::EnumeratedTuple EnumeratedTuple>
constexpr auto get( EnumeratedTuple &&tp ) {
using index_t = typename std::remove_cvref_t<EnumeratedTuple>::index_t;
static constexpr index_t index = static_cast<index_t>(Idx);
static constexpr index_t index = static_cast<index_t>( Idx );
using value_t = decltype( std::get<Idx>( DAW_FWD( tp ).m_tuple ) );
return daw::enumerate_tuple_element_t<value_t, index>{
std::get<Idx>( DAW_FWD( tp ).m_tuple )};
std::get<Idx>( DAW_FWD( tp ).m_tuple ) };
}

template<std::size_t I, daw::EnumeratedTupleElement EnumeratedTupleElement>
constexpr decltype(auto) get( EnumeratedTupleElement &&element ) {
if constexpr(I == 0) {
constexpr decltype( auto ) get( EnumeratedTupleElement &&element ) {
if constexpr( I == 0 ) {
return element.index;
} else {
return DAW_FWD( element ).value;
}
}

}
} // namespace std
6 changes: 3 additions & 3 deletions include/daw/compressed_pair.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ namespace daw {
using Base2 = compressed_pair_elem<T2, 1>;

template<bool D = true>
requires( std::is_default_constructible_v<T1>
and std::is_default_constructible_v<T2> ) //
explicit constexpr compressed_pair( )
requires( std::is_default_constructible_v<T1> and
std::is_default_constructible_v<T2> )
explicit constexpr compressed_pair( )
: Base1( value_init_tag( ) )
, Base2( value_init_tag( ) ) {}

Expand Down
Loading
Loading