Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
92309a3
Merge pull request #562 from beached/master
beached Dec 28, 2025
a90735c
Return released pointer from `observer_ptr::release` and adjust deduc…
beached Dec 29, 2025
4735887
Add `get_out` method to `observer_ptr` to retrieve pointer address.
beached Dec 30, 2025
e7d6aa7
Make `get_out` method in `observer_ptr` non-const for consistent muta…
beached Dec 30, 2025
45ed3df
Refactor concept definitions for clarity and add `explicitly_converti…
beached Jan 2, 2026
b3996de
Standardize formatting in `explicitly_convertible_to` concept definit…
beached Jan 2, 2026
cda2986
newline at end of file in `daw_concepts.h`.
beached Jan 2, 2026
41d9c71
Add `span_writer` utility for writing to spans with variadic argument…
beached Jan 2, 2026
5c04f74
Include `daw_ensure.h` in `daw_span_writer.h` to ensure precondition …
beached Jan 2, 2026
9fd8e31
Add `span_writer_ntz` utility to `daw_span_writer.h` for writing stri…
beached Jan 2, 2026
a810b01
Add `output_span` utility to `daw_span_writer.h` for enhanced span wr…
beached Jan 3, 2026
c39f9ff
Remove unused `DAW_ATTRIB_ENABLE_IF`-dependent code and related direc…
beached Jan 3, 2026
af166ce
Expand `output_span` with additional type aliases, iterator support, …
beached Jan 3, 2026
1555084
Add overload to `output_span` constructor with size constraint valida…
beached Jan 4, 2026
8ae0969
Rename `output_span` to `span_writer` and update associated methods f…
beached Jan 4, 2026
33a50c8
Add `create_bitset_from_set_positions` utility to `daw_bitset_helper.…
beached Jan 4, 2026
2ac0191
Refactor `create_bitset_from_set_positions` to support enums with `In…
beached Jan 4, 2026
b9c7011
Align `DAW_CPP23_CX_BITSET_CX` macro usage and replace with `DAW_CPP2…
beached Jan 4, 2026
44acbfd
Add `First` pipeline utility and corresponding tests. Update feature …
beached Jan 4, 2026
889dce1
Refactor `First` pipeline utility to use `pimpl::FirstFn` implementat…
beached Jan 4, 2026
cf7df49
Introduce `FirstRef` utility to `daw::pipelines` and update tests to …
beached Jan 4, 2026
0fd6757
Refactor `contiguous_view` with updated constructors to allow a subse…
beached Jan 4, 2026
a246534
Add variadic overload to `create_bitset_from_set_positions` and impro…
beached Jan 4, 2026
b862942
Update `contiguous_view` to improve type deduction for const containe…
beached Jan 4, 2026
12bf6ed
Refactor `contiguous_view` to add constructor for subset ranges with …
beached Jan 4, 2026
4eb4e5b
Add `Copy` pipeline utility and `unique_range` implementation, refact…
beached Jan 4, 2026
ea6fb75
Add `forward_lvalue` utility to improve handling of rvalue references…
beached Jan 4, 2026
8b00adb
Add `maybe_unique_ptr` implementation, corresponding helper functions…
beached Jan 7, 2026
583840b
Add `print_log` utility to log formatted output to `std::clog` and up…
beached Jan 7, 2026
17842e7
Add `elements` pipeline utility with iterator implementation, update …
beached Jan 24, 2026
7947234
Add `Element` pipeline utility with iterator/view implementations, up…
beached Jan 24, 2026
1898b5e
Add `CacheLast` pipeline utility with iterator/view implementations, …
beached Jan 28, 2026
e70afe1
Refactor span writer and pipelines tests to enhance size calculations…
beached Jan 28, 2026
a345c37
Add `forward_like` utility with type transformation traits and refact…
beached Jan 29, 2026
7670582
Fixed `zip_iterator` to use `zip_indices` for decrement operations
beached Jan 29, 2026
fdf1b2f
Ensure `std::ranges::distance` conversions are explicitly cast to `st…
beached Jan 29, 2026
1cc0fc2
Add `daw_dbg_ensure` macro and integrate validations in `c_str_proxy`…
beached Feb 1, 2026
278f773
Fixed bug
beached Feb 1, 2026
ff48d5a
Added define switch to disable debug checks of zterm string length ma…
beached Feb 1, 2026
329d149
Was checking the wrong string in new debug check. Fixed
beached Feb 1, 2026
9c23a7e
Added missing include `daw_ensure.h` to string_view
beached Feb 1, 2026
67ddaa9
Include `<span>` header in `daw_safe_pointer.h`
beached Feb 3, 2026
023ffdb
Merge remote-tracking branch 'origin/v2' into v2
beached Feb 3, 2026
600f270
Refactor pipelines and iterator traits to improve const-correctness a…
beached Feb 12, 2026
dcd3b06
Refactor pipeline test to replace `std::from_range` with explicit ite…
beached Feb 12, 2026
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
68 changes: 68 additions & 0 deletions include/daw/daw_bitset_helper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) Darrell Wright
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/beached/header_libraries
//

#pragma once

#include "daw/daw_cpp_feature_check.h"
#include "daw/daw_ensure.h"
#include "daw/traits/daw_traits_integer_type.h"

#include <bitset>
#include <ranges>

namespace daw {
namespace create_bs_impl {
template<std::size_t N>
DAW_CPP23_CX_BITSET_FN auto
create_bitset_from_set_positions( auto const &r ) {
auto result = std::bitset<N>{ };
for( auto const &position : r ) {
#ifndef NDEBUG
using value_t = daw::traits::integral_type_t<
std::ranges::range_value_t<decltype( r )>>;
daw_ensure( ( std::is_unsigned_v<value_t> or
static_cast<value_t>( position ) >= 0 ) );
daw_ensure( static_cast<std::size_t>( position ) < N );
#endif
result.set( static_cast<std::size_t>( position ) );
}
return result;
}
} // namespace create_bs_impl

template<std::size_t N, typename R>
requires( std::ranges::range<R>
and daw::traits::IntegerEnum<std::ranges::range_value_t<R>> ) //
DAW_ATTRIB_FLATTEN DAW_CPP23_CX_BITSET_FN
auto create_bitset_from_set_positions( R const &r ) {
return create_bs_impl::create_bitset_from_set_positions<N>( r );
}

template<std::size_t N, daw::traits::IntegerEnum T>
DAW_ATTRIB_FLATTEN DAW_CPP23_CX_BITSET_FN auto
create_bitset_from_set_positions( std::initializer_list<T> r ) {
return create_bs_impl::create_bitset_from_set_positions<N>( r );
}

template<std::size_t N>
DAW_ATTRIB_FLATTEN DAW_CPP23_CX_BITSET_FN auto
create_bitset_from_set_positions( traits::IntegerEnum auto... positions ) {
auto result = std::bitset<N>{ };
( result.set( [&]( auto position ) {
#ifndef NDEBUG
using value_t = daw::traits::integral_type_t<decltype( position )>;
daw_ensure( ( std::is_unsigned_v<value_t> or
static_cast<value_t>( position ) >= 0 ) );
daw_ensure( static_cast<std::size_t>( position ) < N );
#endif
return static_cast<std::size_t>( position );
}( positions ) ),
... );
return result;
}
} // namespace daw
48 changes: 28 additions & 20 deletions include/daw/daw_concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ namespace daw {
/***
* @brief Given types From and To and an expression E whose type and value
* category are the same as those of std::declval<From>(),
* convertible_to<From, To> requires E to be both implicitly and explicitly
* convertible to type To. The implicit and explicit conversions are required
* to produce equal results.
* explicitly_convertible_to<From, To> requires E to be explicitly
* convertible to type To.
*/
template<typename From, typename To>
concept convertible_to = std::is_convertible_v<From, To> and requires {
{ static_cast<To>( std::declval<From>( ) ) };
concept explicitly_convertible_to = requires {
static_cast<To>( std::declval<From>( ) );
};

/***
Expand All @@ -44,6 +43,17 @@ namespace daw {
template<typename From, typename To>
concept implicitly_convertible_to = std::is_convertible_v<From, To>;

/***
* @brief Given types From and To and an expression E whose type and value
* category are the same as those of std::declval<From>(),
* convertible_to<From, To> requires E to be both implicitly and explicitly
* convertible to type To. The implicit and explicit conversions are required
* to produce equal results.
*/
template<typename From, typename To>
concept convertible_to =
implicitly_convertible_to<From, To> and explicitly_convertible_to<From, To>;

/***
* @brief Satisfied when Lhs and Rhs name the same type (taking into account
* const/volatile qualifications)
Expand Down Expand Up @@ -113,14 +123,14 @@ namespace daw {

template<typename T>
concept ContiguousContainer = requires( T && container ) {
{ std::data( container ) } -> Pointers;
{ std::size( container ) } -> convertible_to<std::size_t>;
{ std::data( container ) }->Pointers;
{ std::size( container ) }->convertible_to<std::size_t>;
};

template<typename T, typename U>
concept ContiguousContainerOf =
ContiguousContainer<T> and requires( T container ) {
{ *std::data( container ) } -> convertible_to<U>;
{ *std::data( container ) }->convertible_to<U>;
};

template<typename T>
Expand Down Expand Up @@ -182,7 +192,7 @@ namespace daw {
std::assignable_from<LHS, RHS>;
#else
std::is_lvalue_reference_v<LHS> and requires( LHS lhs, RHS &&rhs ) {
{ lhs = DAW_FWD( rhs ) } -> std::same_as<LHS>;
{ lhs = DAW_FWD( rhs ) }->std::same_as<LHS>;
};
#endif

Expand Down Expand Up @@ -238,7 +248,7 @@ namespace daw {
movable<I> and requires( I i ) {
typename iter_difference_t<I>;
requires SignedStd<iter_difference_t<I>>;
{ ++i } -> same_as<I &>;
{ ++i }->same_as<I &>;
i++;
};
#endif
Expand All @@ -253,9 +263,7 @@ namespace daw {
*/
template<typename Func, typename Result, typename... Args>
concept invocable_result = requires( Func && f, Args &&...args ) {
{
std::invoke( DAW_FWD( f ), DAW_FWD( args )... )
} -> convertible_to<Result>;
{ std::invoke( DAW_FWD( f ), DAW_FWD( args )... ) }->convertible_to<Result>;
};

template<typename I>
Expand Down Expand Up @@ -358,18 +366,18 @@ namespace daw {
template<typename B>
concept boolean_testable =
concept_details::boolean_testable_impl<B> and requires( B && b ) {
{ not DAW_FWD( b ) } -> concept_details::boolean_testable_impl;
{ not DAW_FWD( b ) }->concept_details::boolean_testable_impl;
};

namespace concept_details {
template<typename T, typename U>
concept weakly_equality_comparable_with =
requires( std::remove_reference_t<T> const &t,
std::remove_reference_t<U> const &u ) {
{ t == u } -> boolean_testable;
{ t != u } -> boolean_testable;
{ u == t } -> boolean_testable;
{ u != t } -> boolean_testable;
{ t == u }->boolean_testable;
{ t != u }->boolean_testable;
{ u == t }->boolean_testable;
{ u != t }->boolean_testable;
};
} // namespace concept_details
#endif
Expand Down Expand Up @@ -439,7 +447,7 @@ namespace daw {

template<typename R, typename Fn, typename... Args>
concept Callable_r = requires( Fn fn, Args... args ) {
{ fn( args... ) } -> convertible_to<R>;
{ fn( args... ) }->convertible_to<R>;
};

template<typename Fn, typename... Args>
Expand All @@ -457,4 +465,4 @@ namespace daw {
{ fn( args... ) } noexcept;
};
} // namespace daw
#endif
#endif
77 changes: 53 additions & 24 deletions include/daw/daw_contiguous_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

#pragma once

#include "daw_concepts.h"
#include "daw_consteval.h"
#include "daw_data_end.h"
#include "daw_utility.h"
#include "impl/daw_view_tags.h"
#include "wrap_iter.h"
#include "daw/daw_concepts.h"
#include "daw/daw_consteval.h"
#include "daw/daw_data_end.h"
#include "daw/daw_ensure.h"
#include "daw/daw_utility.h"
#include "daw/impl/daw_view_tags.h"
#include "daw/wrap_iter.h"

#include <algorithm>
#include <cassert>
Expand All @@ -27,7 +28,8 @@ namespace daw {
struct contiguous_view;

template<typename T, bool ExplicitConv>
requires( not std::is_const_v<T> ) struct contiguous_view<T, ExplicitConv> {
requires( not std::is_const_v<T> ) //
struct contiguous_view<T, ExplicitConv> {
using value_type = T;
using reference = value_type &;
using const_reference = value_type const &;
Expand All @@ -45,7 +47,8 @@ namespace daw {
pointer m_last = nullptr;

public:
contiguous_view( ) = default;
explicit contiguous_view( ) = default;

constexpr contiguous_view( contiguous_view &other ) noexcept
: m_first( other.m_first )
, m_last( other.m_last ) {}
Expand All @@ -70,6 +73,15 @@ namespace daw {
: m_first( std::data( c ) )
, m_last( daw::data_end( c ) ) {}

template<ContiguousContainerOf<value_type> Container>
requires( not_cvref_of<contiguous_view, Container> ) explicit(
ExplicitConv ) constexpr contiguous_view( Container &&c,
std::size_t count ) noexcept
: m_first( std::data( c ) )
, m_last( std::next( m_first, static_cast<difference_type>( count ) ) ) {
daw_ensure( count <= std::size( c ) );
}

template<constructible_from<pointer, size_type> Container>
explicit constexpr operator Container( ) const noexcept {
return Container{ data( ), size( ) };
Expand Down Expand Up @@ -226,7 +238,7 @@ namespace daw {
}

constexpr void remove_prefix( std::size_t count ) noexcept {
count = ( std::min )( count, size( ) );
count = (std::min)( count, size( ) );
m_first += count;
}

Expand All @@ -241,7 +253,7 @@ namespace daw {
}

constexpr void remove_suffix( std::size_t count ) noexcept {
count = ( std::min )( count, size( ) );
count = (std::min)( count, size( ) );
m_last -= count;
}

Expand Down Expand Up @@ -397,8 +409,8 @@ namespace daw {

[[nodiscard]] friend constexpr bool operator<( contiguous_view const &x,
contiguous_view const &y ) {
return std::lexicographical_compare( x.data( ), x.data_end( ), y.data( ),
y.data_end( ) );
return std::lexicographical_compare(
x.data( ), x.data_end( ), y.data( ), y.data_end( ) );
}

[[nodiscard]] friend constexpr bool operator>( contiguous_view const &x,
Expand All @@ -418,8 +430,8 @@ namespace daw {
};

template<typename T, bool ExplicitConv>
requires( std::is_const_v<T> ) struct contiguous_view<T, ExplicitConv> {

requires( std::is_const_v<T> ) //
struct contiguous_view<T, ExplicitConv> {
using value_type = T;
using reference = value_type &;
using const_reference = value_type const &;
Expand Down Expand Up @@ -458,6 +470,15 @@ namespace daw {
: m_first( std::data( c ) )
, m_last( daw::data_end( c ) ) {}

template<ContiguousContainerOf<value_type> Container>
requires( not_cvref_of<contiguous_view, Container> ) explicit(
ExplicitConv ) constexpr contiguous_view( Container &&c,
std::size_t count ) noexcept
: m_first( std::data( c ) )
, m_last( std::next( m_first, static_cast<difference_type>( count ) ) ) {
daw_ensure( count <= std::size( c ) );
}

template<constructible_from<pointer, size_type> Container>
explicit constexpr operator Container( ) const noexcept {
return Container{ data( ), size( ) };
Expand Down Expand Up @@ -593,7 +614,7 @@ namespace daw {
}

constexpr void remove_prefix( std::size_t count ) noexcept {
count = ( std::min )( count, size( ) );
count = (std::min)( count, size( ) );
m_first += count;
}

Expand All @@ -608,7 +629,7 @@ namespace daw {
}

constexpr void remove_suffix( std::size_t count ) noexcept {
count = ( std::min )( count, size( ) );
count = (std::min)( count, size( ) );
m_last -= count;
}

Expand Down Expand Up @@ -764,8 +785,8 @@ namespace daw {

[[nodiscard]] friend constexpr bool operator<( contiguous_view const &x,
contiguous_view const &y ) {
return std::lexicographical_compare( x.data( ), x.data_end( ), y.data( ),
y.data_end( ) );
return std::lexicographical_compare(
x.data( ), x.data_end( ), y.data( ), y.data_end( ) );
}

[[nodiscard]] friend constexpr bool operator>( contiguous_view const &x,
Expand All @@ -784,18 +805,26 @@ namespace daw {
}
};

template<typename T>
contiguous_view( T *, T * ) -> contiguous_view<T>;
template<Pointers P>
contiguous_view( P, P ) -> contiguous_view<std::remove_pointer_t<P>>;

template<typename T>
contiguous_view( T *, std::size_t ) -> contiguous_view<T>;
template<Pointers P, IntegralStd SizeT>
contiguous_view( P, SizeT ) -> contiguous_view<std::remove_pointer_t<P>>;

template<ContiguousContainer Container>
contiguous_view( Container &&c )
-> contiguous_view<std::remove_reference_t<decltype( *std::data( c ) )>>;
contiguous_view( Container &&c ) -> contiguous_view<std::conditional_t<
std::is_const_v<std::remove_reference_t<Container>>,
daw::range_value_t<Container> const, daw::range_value_t<Container>>>;

template<ContiguousContainer Container, IntegralStd SizeT>
contiguous_view( Container &&c, SizeT ) -> contiguous_view<std::conditional_t<
std::is_const_v<std::remove_reference_t<Container>>,
daw::range_value_t<Container> const, daw::range_value_t<Container>>>;

template<typename T, std::size_t N>
contiguous_view( T ( & )[N] ) -> contiguous_view<T>;

template<typename T, std::size_t N>
contiguous_view( T ( & )[N], std::size_t ) -> contiguous_view<T>;
} // namespace daw
DAW_UNSAFE_BUFFER_FUNC_STOP
18 changes: 18 additions & 0 deletions include/daw/daw_cpp_feature_check.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,22 @@ inline constexpr bool daw_has_cx_cmath = false;
#if __cpp_lib_move_only_function >= 202110L
#define DAW_HAS_CPP23_MOVE_ONLY_FUNCTION
#endif
#endif

#if defined( __cpp_lib_constexpr_bitset )
#if __cpp_lib_constexpr_bitset >= 202202L
#define DAW_HAS_CPP23_CONSTEXPR_BITSET 1
#endif
#endif

#if defined( DAW_HAS_CPP23_CONSTEXPR_BITSET )
#define DAW_CPP23_CX_BITSET_FN constexpr
#define DAW_CPP23_CX_BITSET constexpr
#else
#define DAW_CPP23_CX_BITSET_FN inline
#define DAW_CPP23_CX_BITSET
#endif

#if __cpp_lib_optional >= 202506L
#define DAW_HAS_CPP26_OPTIONAL_REFS
#endif
Loading
Loading