Skip to content

Commit

Permalink
Merge pull request #517 from beached/v2
Browse files Browse the repository at this point in the history
Split out traits_concepts and moved from details
  • Loading branch information
beached committed Jan 7, 2024
2 parents 3bd77f3 + 7eff852 commit 89e330c
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 172 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
cmake_minimum_required( VERSION 3.14 )

project( "daw-header-libraries"
VERSION "2.98.2"
VERSION "2.98.3"
DESCRIPTION "Various headers"
HOMEPAGE_URL "https://github.com/beached/header_libraries"
LANGUAGES C CXX
Expand Down
2 changes: 1 addition & 1 deletion include/daw/daw_fixed_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "ciso646.h"
#include "daw_exchange.h"
#include "daw_move.h"
#include "daw_traits.h"
#include "daw_traits_concepts.h"
#include "iterator/daw_pointer_iterator.h"

#include <algorithm>
Expand Down
42 changes: 19 additions & 23 deletions include/daw/daw_string_view2.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "daw_string_view2_fwd.h"

#include "ciso646.h"
// #include "daw_algorithm.h"
#include "daw_assume.h"
#include "daw_check_exceptions.h"
#include "daw_compiler_fixups.h"
Expand All @@ -21,7 +20,6 @@
#include "daw_likely.h"
#include "daw_logic.h"
#include "daw_move.h"
#include "daw_swap.h"
#include "daw_traits.h"
#include "impl/daw_algorithm_copy.h"
#include "impl/daw_algorithm_find.h"
Expand Down Expand Up @@ -375,14 +373,14 @@ namespace daw {
using is_last_a_pointer =
std::bool_constant<B == string_view_bounds_type::pointer>;

using last_type = conditional_t<is_last_a_pointer<BoundsType>::value,
const_pointer, size_type>;
using last_type = daw::conditional_t<is_last_a_pointer<BoundsType>::value,
const_pointer, size_type>;

using default_last_t = std::integral_constant<last_type, last_type{ }>;

using last_difference_type =
conditional_t<is_last_a_pointer<BoundsType>::value, difference_type,
size_type>;
daw::conditional_t<is_last_a_pointer<BoundsType>::value,
difference_type, size_type>;

template<string_view_bounds_type Bounds, typename LastType>
DAW_ATTRIB_INLINE static constexpr last_type
Expand Down Expand Up @@ -2366,15 +2364,6 @@ namespace daw {
return compare( rhs ) == 0;
}

#if defined( DAW_HAS_CPP20_3WAY_COMPARE )
// clang-format off
[[nodiscard]] constexpr std::strong_ordering
operator<=>( basic_string_view const &rhs ) const noexcept {
return compare( rhs ) <=> 0;
}
// clang-format on
#endif

template<typename StringView,
DAW_REQ_CONTIG_CHAR_RANGE( StringView, CharT )>
[[nodiscard]] friend constexpr bool
Expand Down Expand Up @@ -2406,6 +2395,15 @@ namespace daw {
.compare( rhs ) != 0;
}

#if defined( DAW_HAS_CPP20_3WAY_COMPARE )
// clang-format off
[[nodiscard]] constexpr std::strong_ordering
operator<=>( basic_string_view const &rhs ) const noexcept {
return compare( rhs ) <=> 0;
}
// clang-format on
#else

[[nodiscard]] constexpr bool operator<( basic_string_view rhs ) noexcept {
return compare( rhs ) < 0;
}
Expand Down Expand Up @@ -2475,7 +2473,7 @@ namespace daw {
return basic_string_view( std::data( lhs ), std::size( lhs ) )
.compare( rhs ) >= 0;
}

#endif
private:
struct is_space {
inline constexpr bool operator( )( CharT c ) const noexcept {
Expand Down Expand Up @@ -2629,14 +2627,12 @@ namespace daw {

namespace sv2_details {
template<typename OStream,
std::enable_if_t<daw::traits::is_ostream_like_lite_v<OStream>,
std::enable_if_t<traits::is_ostream_like_lite_v<OStream>,
std::nullptr_t> = nullptr>
inline void sv_insert_fill_chars( OStream &os, std::size_t n ) {
using CharT = typename OStream::char_type;
static_assert(
traits::traits_details::ostream_detectors::has_write_member_v<OStream,
CharT>,
"OStream Must has write member" );
static_assert( traits::has_write_member_v<OStream, CharT>,
"OStream Must has write member" );

constexpr std::size_t fill_chars_sz = 8;
CharT fill_chars[fill_chars_sz] = { };
Expand All @@ -2656,7 +2652,7 @@ namespace daw {

template<typename OStream, typename CharT,
daw::string_view_bounds_type Bounds,
std::enable_if_t<daw::traits::is_ostream_like_v<OStream, CharT>,
std::enable_if_t<traits::is_ostream_like_v<OStream, CharT>,
std::nullptr_t> = nullptr>
void sv_insert_aligned( OStream &os,
daw::sv2::basic_string_view<CharT, Bounds> str ) {
Expand All @@ -2682,7 +2678,7 @@ namespace daw {
} // namespace sv2_details

template<typename CharT, string_view_bounds_type Bounds, typename OStream,
std::enable_if_t<daw::traits::is_ostream_like_v<OStream, CharT>,
std::enable_if_t<traits::is_ostream_like_v<OStream, CharT>,
std::nullptr_t> = nullptr>
OStream &operator<<( OStream &os, basic_string_view<CharT, Bounds> v ) {
if( os.good( ) ) {
Expand Down
83 changes: 17 additions & 66 deletions include/daw/daw_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "daw_enable_if.h"
#include "daw_move.h"
#include "impl/daw_conditional.h"
#include "impl/daw_traits_concepts.h"
#include "impl/daw_traits_impl.h"

#include <cstddef>
Expand Down Expand Up @@ -512,77 +511,29 @@ namespace daw::traits {
are_same_types_v<Args...>,
std::is_constructible_v<T, std::initializer_list<first_type<Args...>>>>;

namespace traits_details::ostream_detectors {
template<typename T>
using has_char_type_detect = typename T::char_type;

template<typename T>
using has_adjustfield_detect = decltype( T::adjustfield );

template<typename T>
using has_left_detect = decltype( T::left );

template<typename T>
using has_fill_member_detect = decltype( std::declval<T>( ).fill( ) );

template<typename T>
using has_good_member_detect = decltype( std::declval<T>( ).good( ) );

template<typename T, typename CharT>
using has_write_member_detect = decltype( std::declval<T>( ).write(
std::declval<CharT const *>( ), std::declval<int>( ) ) );

template<typename T>
using has_width_member_detect = decltype( std::declval<T>( ).width( ) );

template<typename T>
using has_flags_member_detect = decltype( std::declval<T>( ).flags( ) );

template<typename T>
inline constexpr bool has_adjustfield_v =
daw::is_detected_v<has_adjustfield_detect, T>;

template<typename T>
inline constexpr bool has_left_v = daw::is_detected_v<has_left_detect, T>;

template<typename T>
inline constexpr bool has_char_type_v =
daw::is_detected_v<has_char_type_detect, T>;

template<typename T>
inline constexpr bool has_fill_member_v =
daw::is_detected_v<has_fill_member_detect, T>;
template<typename, typename = void>
inline constexpr bool is_ostream_like_lite_v = false;

template<typename T>
inline constexpr bool has_good_member_v =
daw::is_detected_v<has_good_member_detect, T>;

template<typename T, typename CharT>
inline constexpr bool has_write_member_v =
daw::is_detected_v<has_write_member_detect, T, CharT>;
template<typename T>
inline constexpr bool is_ostream_like_lite_v<
T, std::void_t<typename T::char_type, decltype( T::adjustfield ),
decltype( std::declval<T const &>( ).fill( ) ),
decltype( std::declval<T const &>( ).good( ) ),
decltype( std::declval<T const &>( ).width( ) ),
decltype( std::declval<T const &>( ).flags( ) )>> = true;

template<typename T>
inline constexpr bool has_width_member_v =
daw::is_detected_v<has_width_member_detect, T>;
template<typename T, typename CharT, typename = void>
inline constexpr bool has_write_member_v = false;

template<typename T>
inline constexpr bool has_flags_member_v =
daw::is_detected_v<has_flags_member_detect, T>;
} // namespace traits_details::ostream_detectors

template<typename T>
inline constexpr bool is_ostream_like_lite_v =
all_true_v<traits_details::ostream_detectors::has_char_type_v<T>,
traits_details::ostream_detectors::has_adjustfield_v<T>,
traits_details::ostream_detectors::has_fill_member_v<T>,
traits_details::ostream_detectors::has_good_member_v<T>,
traits_details::ostream_detectors::has_width_member_v<T>,
traits_details::ostream_detectors::has_flags_member_v<T>>;
template<typename T, typename CharT>
inline constexpr bool has_write_member_v<
T, CharT,
std::void_t<decltype( std::declval<T &>( ).write(
std::declval<CharT const *>( ), std::declval<int>( ) ) )>> = true;

template<typename T, typename CharT>
inline constexpr bool is_ostream_like_v =
all_true_v<is_ostream_like_lite_v<T>,
traits_details::ostream_detectors::has_write_member_v<T, CharT>>;
is_ostream_like_lite_v<T> and has_write_member_v<T, CharT>;

template<typename T>
inline constexpr bool is_character_v = is_one_of_v<T, char, wchar_t>;
Expand Down
Loading

0 comments on commit 89e330c

Please sign in to comment.