Skip to content

Commit ea79229

Browse files
authored
Merge pull request #559 from beached/v2
Pipelines cleanup and added drop_while/drop_until
2 parents 2b00012 + 38b3e99 commit ea79229

15 files changed

Lines changed: 375 additions & 136 deletions

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
cmake_minimum_required( VERSION 3.14 )
1010

1111
project( "daw-header-libraries"
12-
VERSION "2.131.0"
12+
VERSION "2.132.0"
1313
DESCRIPTION "Various headers"
1414
HOMEPAGE_URL "https://github.com/beached/header_libraries"
1515
LANGUAGES C CXX

include/daw/daw_contract.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,21 @@ namespace daw {
5656
public:
5757
#if defined( DAW_ATTRIB_ENABLE_IF )
5858
DAW_CONSTEVAL contract( T v )
59-
DAW_ATTRIB_ENABLE_IF( __builtin_constant_p( v ), "Constant value" )
60-
DAW_ATTRIB_ENABLE_IF( validate( v ), "Contract violatiion" )
59+
DAW_ATTRIB_ENABLE_IF( __builtin_constant_p( v ) and validate( v ),
60+
"Contract violatiion" )
6161
: value( std::move( v ) ) {}
6262

63-
DAW_ATTRIB_FLATINLINE contract( T v )
64-
DAW_ATTRIB_ENABLE_IF( not __builtin_constant_p( v ),
65-
"Value isn't a constant" )
63+
DAW_ATTRIB_FLATINLINE constexpr contract( T v )
64+
DAW_ATTRIB_ENABLE_IF( not __builtin_constant_p( v ), " " )
6665
: value( std::move( v ) ) {
6766
if( not validate( value ) ) {
6867
contract_failure( );
6968
}
7069
}
7170
#if defined( DAW_HAS_CPP26_DELETED_REASON )
72-
DAW_CONSTEVAL contract( T v )
73-
DAW_ATTRIB_ENABLE_IF( __builtin_constant_p( v ), "Constant value" )
74-
DAW_ATTRIB_ENABLE_IF( not validate( v ), "Contract violatiion" ) =
75-
delete( "Contract violation" );
71+
DAW_CONSTEVAL contract( T v ) DAW_ATTRIB_ENABLE_IF(
72+
__builtin_constant_p( v ) and not validate( v ),
73+
"Contract violatiion" ) = delete( "Contract violation" );
7674
#endif
7775
#else
7876
DAW_ATTRIB_FLATINLINE constexpr contract( T v )

include/daw/daw_ensure.h

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,39 @@
88

99
#pragma once
1010

11-
#include "ciso646.h"
12-
#include "daw_attributes.h"
11+
#include "daw/daw_attributes.h"
12+
#include "daw/daw_cpp_feature_check.h"
1313

1414
#include <exception>
1515

1616
namespace daw::ensure {
17-
[[noreturn]] DAW_ATTRIB_NOINLINE inline void do_error( ) {
17+
#if defined( DAW_ATTRIB_ENABLE_IF )
18+
#if defined( DAW_HAS_CPP26_DELETED_REASON )
19+
[[noreturn]] DAW_ATTRIB_NOINLINE inline void ensure_error( bool b )
20+
DAW_ATTRIB_ENABLE_IF( __builtin_constant_p( b ) and b,
21+
"Ensure check failed" ) =
22+
delete( "Ensure check failed" );
23+
#endif
24+
[[noreturn]] DAW_ATTRIB_NOINLINE inline void ensure_error( bool b )
25+
DAW_ATTRIB_ENABLE_IF( __builtin_constant_p( b ) and not b,
26+
"Ensure check failed" ) {
1827
std::terminate( );
1928
}
29+
30+
[[noreturn]] DAW_ATTRIB_NOINLINE inline void ensure_error( bool b )
31+
DAW_ATTRIB_ENABLE_IF( not __builtin_constant_p( b ), " " ) {
32+
std::terminate( );
33+
}
34+
#else
35+
[[noreturn]] DAW_ATTRIB_NOINLINE inline void ensure_error( bool ) {
36+
std::terminate( );
37+
}
38+
#endif
2039
} // namespace daw::ensure
2140

22-
#define daw_ensure( ... ) \
23-
do { \
24-
if( not( __VA_ARGS__ ) ) { \
25-
::daw::ensure::do_error( ); \
26-
} \
41+
#define daw_ensure( ... ) \
42+
do { \
43+
if( not( __VA_ARGS__ ) ) { \
44+
::daw::ensure::ensure_error( not( __VA_ARGS__ ) ); \
45+
} \
2746
} while( false )
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) Darrell Wright
2+
//
3+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
4+
// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
//
6+
// Official repository: https://github.com/beached/header_libraries
7+
//
8+
9+
#pragma once
10+
11+
#include "daw/daw_cpp_feature_check.h"
12+
#include "daw/daw_move.h"
13+
14+
namespace daw {
15+
struct identity_function_t {
16+
explicit identity_function_t() = default;
17+
18+
template<typename T>
19+
DAW_CPP23_STATIC_CALL_OP constexpr T &&
20+
operator( )( T &&value ) DAW_CPP23_STATIC_CALL_OP_CONST {
21+
return DAW_FWD( value );
22+
}
23+
};
24+
25+
inline constexpr auto identity_function = identity_function_t{};
26+
} // namespace daw

include/daw/daw_not_null.h

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,19 @@ namespace daw {
7979
public:
8080
#if defined( DAW_ATTRIB_ENABLE_IF )
8181
DAW_ATTRIB_INLINE constexpr not_null( pointer_const_reference ptr ) noexcept
82-
DAW_ATTRIB_ENABLE_IF( __builtin_constant_p( ptr ), "Constant value" )
83-
DAW_ATTRIB_ENABLE_IF( ptr != null_value, "Unexpected null value" )
84-
: m_ptr( ptr ) {
85-
if( ptr == null_value ) {
86-
std::terminate( );
87-
}
88-
}
82+
DAW_ATTRIB_ENABLE_IF( __builtin_constant_p( ptr ) and ptr != null_value,
83+
"Unexpected null value" )
84+
: m_ptr( ptr ) {}
8985

9086
#if defined( DAW_HAS_CPP26_DELETED_REASON )
9187
DAW_ATTRIB_INLINE constexpr not_null( pointer_const_reference ptr ) noexcept
92-
DAW_ATTRIB_ENABLE_IF( __builtin_constant_p( ptr ), "Constant value" )
93-
DAW_ATTRIB_ENABLE_IF( ptr == null_value, "Unexpected null value" ) =
94-
delete( "Unexpected null value" );
88+
DAW_ATTRIB_ENABLE_IF( __builtin_constant_p( ptr ) and ptr == null_value,
89+
"Unexpected null value" ) =
90+
delete( "Unexpected null value" );
9591
#endif
9692

9793
DAW_ATTRIB_INLINE constexpr not_null( pointer_const_reference ptr ) noexcept
98-
DAW_ATTRIB_ENABLE_IF( not __builtin_constant_p( ptr ), "" )
94+
DAW_ATTRIB_ENABLE_IF( not __builtin_constant_p( ptr ), " " )
9995
: m_ptr( ptr ) {
10096
if( ptr == null_value ) {
10197
std::terminate( );
@@ -104,27 +100,23 @@ namespace daw {
104100

105101
DAW_ATTRIB_INLINE constexpr not_null &
106102
operator=( pointer_const_reference ptr ) noexcept
107-
DAW_ATTRIB_ENABLE_IF( __builtin_constant_p( ptr ), "Constant value" )
108-
DAW_ATTRIB_ENABLE_IF( ptr != null_value, "Unexpected null value" ) {
103+
DAW_ATTRIB_ENABLE_IF( __builtin_constant_p( ptr ) and ptr != null_value,
104+
"Unexpected null value" ) {
109105
m_ptr = ptr;
110-
if( ptr == null_value ) {
111-
std::terminate( );
112-
}
113106
return *this;
114107
}
115108

116109
#if defined( DAW_HAS_CPP26_DELETED_REASON )
117110
DAW_ATTRIB_INLINE constexpr not_null &
118111
operator=( pointer_const_reference ptr ) noexcept
119-
DAW_ATTRIB_ENABLE_IF( __builtin_constant_p( ptr ), "Constant value" )
120-
DAW_ATTRIB_ENABLE_IF( ptr == null_value, "Unexpected null value" ) =
121-
delete( "Unexpected null value" );
112+
DAW_ATTRIB_ENABLE_IF( __builtin_constant_p( ptr ) and ptr == null_value,
113+
"Unexpected null value" ) =
114+
delete( "Unexpected null value" );
122115
#endif
123116

124117
DAW_ATTRIB_INLINE constexpr not_null &
125118
operator=( pointer_const_reference ptr ) noexcept
126-
DAW_ATTRIB_ENABLE_IF( not __builtin_constant_p( ptr ),
127-
"Constant value" ) {
119+
DAW_ATTRIB_ENABLE_IF( not __builtin_constant_p( ptr ), " " ) {
128120
m_ptr = ptr;
129121
if( ptr == null_value ) {
130122
std::terminate( );

include/daw/daw_pipelines.h

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,32 @@
88

99
#pragma once
1010

11-
#include "pipelines/algorithm.h"
12-
#include "pipelines/chunk.h"
13-
#include "pipelines/concat.h"
14-
#include "pipelines/enumerate.h"
15-
#include "pipelines/every.h"
16-
#include "pipelines/filter.h"
17-
#include "pipelines/find.h"
18-
#include "pipelines/flatten.h"
19-
#include "pipelines/foreach.h"
20-
#include "pipelines/generate.h"
21-
#include "pipelines/iota.h"
22-
#include "pipelines/map.h"
23-
#include "pipelines/maybe.h"
24-
#include "pipelines/numeric.h"
25-
#include "pipelines/pipeline.h"
26-
#include "pipelines/predicates.h"
27-
#include "pipelines/print.h"
28-
#include "pipelines/range.h"
29-
#include "pipelines/reverse.h"
30-
#include "pipelines/sample.h"
31-
#include "pipelines/skip.h"
32-
#include "pipelines/slide.h"
33-
#include "pipelines/split.h"
34-
#include "pipelines/swizzle.h"
35-
#include "pipelines/take.h"
36-
#include "pipelines/to.h"
37-
#include "pipelines/unique.h"
38-
#include "pipelines/zip.h"
11+
#include "daw/pipelines/algorithm.h"
12+
#include "daw/pipelines/chunk.h"
13+
#include "daw/pipelines/concat.h"
14+
#include "daw/pipelines/drop.h"
15+
#include "daw/pipelines/enumerate.h"
16+
#include "daw/pipelines/every.h"
17+
#include "daw/pipelines/filter.h"
18+
#include "daw/pipelines/find.h"
19+
#include "daw/pipelines/flatten.h"
20+
#include "daw/pipelines/foreach.h"
21+
#include "daw/pipelines/generate.h"
22+
#include "daw/pipelines/iota.h"
23+
#include "daw/pipelines/map.h"
24+
#include "daw/pipelines/maybe.h"
25+
#include "daw/pipelines/numeric.h"
26+
#include "daw/pipelines/pipeline.h"
27+
#include "daw/pipelines/predicates.h"
28+
#include "daw/pipelines/print.h"
29+
#include "daw/pipelines/range.h"
30+
#include "daw/pipelines/reverse.h"
31+
#include "daw/pipelines/sample.h"
32+
#include "daw/pipelines/skip.h"
33+
#include "daw/pipelines/slide.h"
34+
#include "daw/pipelines/split.h"
35+
#include "daw/pipelines/swizzle.h"
36+
#include "daw/pipelines/take.h"
37+
#include "daw/pipelines/to.h"
38+
#include "daw/pipelines/unique.h"
39+
#include "daw/pipelines/zip.h"

include/daw/daw_string_view.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2263,7 +2263,6 @@ namespace daw {
22632263
DAW_REQ_UNARY_PRED_REQ( UnaryPredicate, CharT )
22642264
[[nodiscard]] constexpr size_type
22652265
find_first_not_of_if( UnaryPredicate pred, size_type pos = 0 ) const {
2266-
traits::is_unary_predicate_test<UnaryPredicate, CharT>( );
22672266

22682267
if( pos >= size( ) ) {
22692268
return npos;

include/daw/daw_visit_as.h

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright (c) Darrell Wright
2+
//
3+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
4+
// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
//
6+
// Official repository: https://github.com/beached/header_libraries
7+
//
8+
9+
#pragma once
10+
11+
#include <daw/daw_bit_cast.h>
12+
#include <daw/daw_move.h>
13+
14+
#include <functional>
15+
16+
17+
#if defined( DAW_CX_BIT_CAST )
18+
#define DAW_CX_IF_BIT_CAST constexpr
19+
#else
20+
#define DAW_CX_IF_BIT_CAST
21+
#endif
22+
23+
namespace daw {
24+
/**
25+
* @brief Invokes a visitor on a reinterpretation of the provided value, allowing
26+
* modification of the value via the provided visitor, and optionally
27+
* returning a value from the visitor's result.
28+
*
29+
* @tparam VisitedT The type to reinterpreted `value` as when invoking the visitor.
30+
* @tparam OrigT The original type of the `value` being modified or accessed.
31+
* @tparam Visitor The invocable type that will be applied to the value.
32+
*
33+
* @param value A reference to the value being visited and potentially modified.
34+
* @param visitor A invocable that processes the value once reinterpreted as
35+
* type `VisitedT`.
36+
*
37+
* @return The result of invoking the visitor if the visitor returns a non-void
38+
* value; otherwise, nothing is returned.
39+
*
40+
* @details The function performs a bit cast to reinterpret `value` as type
41+
* `VisitedT`. It then applies the visitor to this reinterpreted value.
42+
* After the visitor processes the value, the function updates the
43+
* original value with the potentially modified value. If the visitor
44+
* returns a result, it is also returned by this function.
45+
*/
46+
template<typename VisitedT, typename OrigT, typename Visitor>
47+
DAW_CX_IF_BIT_CAST auto visit_as( OrigT &value, Visitor &&visitor ) {
48+
auto tmp = daw::bit_cast<VisitedT>( value );
49+
if constexpr( std::is_void_v<std::invoke_result_t<Visitor, VisitedT &>> ) {
50+
std::invoke( DAW_FWD( visitor ), tmp );
51+
value = daw::bit_cast<OrigT>( tmp );
52+
} else {
53+
auto result = std::invoke( DAW_FWD( visitor ), tmp );
54+
value = daw::bit_cast<OrigT>( tmp );
55+
return result;
56+
}
57+
}
58+
59+
60+
/**
61+
* @brief Invokes a visitor on a reinterpretation of the provided value.
62+
*
63+
* @tparam VisitedT The type to reinterpret `value` as when invoking the visitor.
64+
* @tparam OrigT The original type of the `value`.
65+
* @tparam Visitor The callable type that will be applied to the reinterpreted value.
66+
*
67+
* @param value A constant reference to the value being reinterpreted and visited.
68+
* @param visitor A callable object that operates on the reinterpreted value.
69+
*
70+
* @return The result of invoking the visitor with the reinterpreted value.
71+
*
72+
* @details This function performs a bit-cast of `value` to the type `VisitedT` and
73+
* then applies the visitor to the reinterpreted value. The result of the
74+
* visitor is returned if it produces a value.
75+
*/
76+
template<typename VisitedT, typename OrigT, typename Visitor>
77+
DAW_CX_IF_BIT_CAST auto visit_as( OrigT const &value, Visitor &&visitor ) {
78+
auto const tmp = daw::bit_cast<VisitedT>( value );
79+
return std::invoke( DAW_FWD( visitor ), tmp );
80+
}
81+
} // namespace daw

include/daw/iterator/daw_reverse_iterator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace daw {
2525
using reference = typename std::iterator_traits<Iterator>::reference;
2626
using iterator_category =
2727
typename std::iterator_traits<Iterator>::iterator_category;
28-
28+
using i_am_a_daw_reverse_iterator = void;
2929
private:
3030
Iterator m_base{ };
3131

include/daw/pipelines/drop.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) Darrell Wright
2+
//
3+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
4+
// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
5+
//
6+
// Official repository: https://github.com/beached/header_libraries
7+
//
8+
9+
#pragma once
10+
11+
#include "daw/daw_move.h"
12+
#include "daw/pipelines/range.h"
13+
14+
namespace daw::pipelines {
15+
template<typename Pred>
16+
constexpr auto drop_while( Pred &&p ) {
17+
return [pred = DAW_FWD( p )]( auto &&r ) {
18+
auto f = std::begin( r );
19+
auto l = std::end( r );
20+
while( f != l and pred( *f ) ) {
21+
++f;
22+
}
23+
return range_t{ std::move( f ), std::move( l ) };
24+
};
25+
}
26+
27+
template<typename Pred>
28+
constexpr auto drop_until( Pred &&p ) {
29+
return [pred = DAW_FWD( p )]( auto &&r ) {
30+
auto f = std::begin( r );
31+
auto l = std::end( r );
32+
while( f != l and not pred( *f ) ) {
33+
++f;
34+
}
35+
return range_t{ std::move( f ), std::move( l ) };
36+
};
37+
}
38+
} // namespace daw::pipelines

0 commit comments

Comments
 (0)