diff --git a/include/stdx/bit.hpp b/include/stdx/bit.hpp index 4cc930b..5587bfa 100644 --- a/include/stdx/bit.hpp +++ b/include/stdx/bit.hpp @@ -16,8 +16,6 @@ #include #endif -// NOLINTBEGIN(modernize-use-constraints) - namespace stdx { inline namespace v1 { @@ -241,9 +239,8 @@ using std::bit_width; using std::has_single_bit; #endif -template -[[nodiscard]] constexpr auto to_le(T x) noexcept - -> std::enable_if_t, T> { +template +[[nodiscard]] constexpr auto to_le(T x) noexcept -> T { if constexpr (stdx::endian::native == stdx::endian::big) { return byteswap(x); } else { @@ -251,9 +248,8 @@ template } } -template -[[nodiscard]] constexpr auto to_be(T x) noexcept - -> std::enable_if_t, T> { +template +[[nodiscard]] constexpr auto to_be(T x) noexcept -> T { if constexpr (stdx::endian::native == stdx::endian::little) { return byteswap(x); } else { @@ -261,9 +257,8 @@ template } } -template -[[nodiscard]] constexpr auto from_le(T x) noexcept - -> std::enable_if_t, T> { +template +[[nodiscard]] constexpr auto from_le(T x) noexcept -> T { if constexpr (stdx::endian::native == stdx::endian::big) { return byteswap(x); } else { @@ -271,9 +266,8 @@ template } } -template -[[nodiscard]] constexpr auto from_be(T x) noexcept - -> std::enable_if_t, T> { +template +[[nodiscard]] constexpr auto from_be(T x) noexcept -> T { if constexpr (stdx::endian::native == stdx::endian::little) { return byteswap(x); } else { @@ -463,14 +457,10 @@ constexpr auto bit_destructure_impl(T t, std::index_sequence) { } } // namespace bit_detail -template -constexpr auto bit_destructure(T t) - -> std::enable_if_t, - std::array> { +template +constexpr auto bit_destructure(T t) -> std::array { return bit_detail::bit_destructure_impl()>( t, std::make_index_sequence{}); } } // namespace v1 } // namespace stdx - -// NOLINTEND(modernize-use-constraints) diff --git a/include/stdx/byterator.hpp b/include/stdx/byterator.hpp index 532ff03..fc5b1a4 100644 --- a/include/stdx/byterator.hpp +++ b/include/stdx/byterator.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -11,14 +12,12 @@ #include #include -// NOLINTBEGIN(modernize-use-constraints) - namespace stdx { inline namespace v1 { namespace detail { template -constexpr auto is_byteratorish_v = +concept byteratorish = std::is_base_of_v::iterator_category> and std::is_trivially_copyable_v::value_type>; @@ -41,9 +40,8 @@ template class byterator { byterator const &y) -> bool { return x.ptr == y.ptr; } - template , T>, - int> = 0> + template + requires std::is_same_v, T> [[nodiscard]] friend constexpr auto operator==(byterator const &x, It y) -> bool { return static_cast(x.ptr) == @@ -54,9 +52,8 @@ template class byterator { byterator const &y) { return x.ptr <=> y.ptr; } - template , T>, - int> = 0> + template + requires std::is_same_v, T> [[nodiscard]] friend constexpr auto operator<=>(byterator const &x, It y) { return static_cast(x.ptr) <=> static_cast(stdx::to_address(y)); @@ -69,8 +66,7 @@ template class byterator { using reference = value_type &; using iterator_category = std::random_access_iterator_tag; - template , int> = 0> + template explicit byterator(It it) : ptr(bit_cast(stdx::to_address(it))) {} [[nodiscard]] constexpr auto operator->() const -> byte_t * { return ptr; } @@ -138,8 +134,8 @@ template class byterator { return ptr[n]; } - template , int> = 0> + template + requires std::is_trivially_copyable_v [[nodiscard]] auto peek() -> R { V v; std::memcpy(std::addressof(v), ptr, sizeof(V)); @@ -159,17 +155,16 @@ template class byterator { return advance(n * static_cast(sizeof(V))); } - template , int> = 0> + template + requires std::is_trivially_copyable_v [[nodiscard]] auto read() -> R { R ret = peek(); advance(); return ret; } - template >, - int> = 0> + template + requires std::is_trivially_copyable_v> auto write(V &&v) -> void { using R = remove_cvref_t; std::memcpy(ptr, std::addressof(v), sizeof(R)); @@ -229,10 +224,8 @@ template class byterator { } }; -template , int> = 0> +template byterator(It) -> byterator>; } // namespace v1 } // namespace stdx - -// NOLINTEND(modernize-use-constraints) diff --git a/include/stdx/cx_map.hpp b/include/stdx/cx_map.hpp index 6865cad..2ffbbf4 100644 --- a/include/stdx/cx_map.hpp +++ b/include/stdx/cx_map.hpp @@ -37,10 +37,8 @@ template class cx_map { public: constexpr cx_map() = default; - // NOLINTNEXTLINE(modernize-use-constraints) - template ), - int> = 0> + template ... Vs> + requires(sizeof...(Vs) <= N) constexpr explicit cx_map(Vs const &...vs) : storage{vs...}, current_size{sizeof...(Vs)} {} diff --git a/include/stdx/cx_set.hpp b/include/stdx/cx_set.hpp index 8b0effc..914d86f 100644 --- a/include/stdx/cx_set.hpp +++ b/include/stdx/cx_set.hpp @@ -23,14 +23,10 @@ template class cx_set { using const_iterator = value_type const *; constexpr cx_set() = default; - template ), - int> = 0> + template ... Ts> + requires(sizeof...(Ts) <= N) constexpr explicit cx_set(Ts const &...ts) - : storage{static_cast(ts)...}, current_size{sizeof...(Ts)} { - } + : storage{static_cast(ts)...}, current_size{sizeof...(Ts)} {} [[nodiscard]] constexpr auto begin() LIFETIMEBOUND -> iterator { return std::data(storage); diff --git a/include/stdx/cx_vector.hpp b/include/stdx/cx_vector.hpp index ae0024d..ef1bf2d 100644 --- a/include/stdx/cx_vector.hpp +++ b/include/stdx/cx_vector.hpp @@ -30,11 +30,8 @@ template class cx_vector { using const_reverse_iterator = std::reverse_iterator; constexpr cx_vector() = default; - template ), - int> = 0> + template ... Ts> + requires(sizeof...(Ts) <= N) constexpr explicit cx_vector(Ts const &...ts) : storage{static_cast(ts)...}, current_size{sizeof...(Ts)} { } diff --git a/include/stdx/env.hpp b/include/stdx/env.hpp index b414c81..69cb04c 100644 --- a/include/stdx/env.hpp +++ b/include/stdx/env.hpp @@ -49,7 +49,7 @@ template struct autowrap { T value; }; -// NOLINTNEXTLINE(modernize-avoid-c-arrays) +// NOLINTNEXTLINE(*-avoid-c-arrays) template using str_lit_t = char const (&)[N]; template struct autowrap> { diff --git a/include/stdx/functional.hpp b/include/stdx/functional.hpp index 8005f9e..291c947 100644 --- a/include/stdx/functional.hpp +++ b/include/stdx/functional.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include @@ -143,15 +144,12 @@ template constexpr auto bind_back(Args &&...args) { {std::forward(args)...}}; } -// NOLINTBEGIN(modernize-use-constraints) template struct unary_plus { - template >> + template U> constexpr auto operator()(U &&u) const -> decltype(+std::forward(u)) { return +std::forward(u); } }; -// NOLINTEND(modernize-use-constraints) template <> struct unary_plus { using is_transparent = int; @@ -172,15 +170,12 @@ constexpr inline struct safe_identity_t { } } safe_identity; -// NOLINTBEGIN(modernize-use-constraints) template struct dereference { - template >> + template U> constexpr auto operator()(U &&u) const -> decltype(*std::forward(u)) { return *std::forward(u); } }; -// NOLINTEND(modernize-use-constraints) template <> struct dereference { using is_transparent = int; diff --git a/include/stdx/iterator.hpp b/include/stdx/iterator.hpp index 4a6b97b..da7a324 100644 --- a/include/stdx/iterator.hpp +++ b/include/stdx/iterator.hpp @@ -24,7 +24,7 @@ constexpr auto ct_capacity_v = detail::ct_capacity_fail{}; template constexpr auto ct_capacity_v> = N; -// NOLINTNEXTLINE(modernize-avoid-c-arrays) +// NOLINTNEXTLINE(*-avoid-c-arrays) template constexpr auto ct_capacity_v = N; template constexpr auto ct_capacity_v = ct_capacity_v; diff --git a/include/stdx/optional.hpp b/include/stdx/optional.hpp index 7542ea6..00a5b49 100644 --- a/include/stdx/optional.hpp +++ b/include/stdx/optional.hpp @@ -10,8 +10,6 @@ #include #include -// NOLINTBEGIN(modernize-use-constraints) - namespace stdx { inline namespace v1 { template struct tombstone_traits { @@ -110,12 +108,11 @@ template > class optional { constexpr explicit optional(std::in_place_t, Args &&...args) : val{std::forward(args)...} {} - template < - typename U = T, - typename = std::enable_if_t< + template + requires( std::is_constructible_v and not std::is_same_v, std::in_place_t> and - not std::is_same_v, optional>>> + not std::is_same_v, optional>) constexpr explicit optional(U &&u) : val{std::forward(u)} {} constexpr auto operator=(std::nullopt_t) -> optional & { @@ -123,12 +120,12 @@ template > class optional { return *this; } - template < - typename U = T, - typename = std::enable_if_t< - std::is_constructible_v and std::is_assignable_v and - not std::is_same_v, optional> and - (std::is_scalar_v or not std::is_same_v, T>)>> + template + requires(std::is_constructible_v and + std::is_assignable_v and + not std::is_same_v, optional> and + (std::is_scalar_v or + not std::is_same_v, T>)) constexpr auto operator=(U &&u) -> optional & { val = std::forward(u); return *this; @@ -312,7 +309,7 @@ template optional(T) -> optional; namespace detail { template -constexpr bool optional_like = +concept optional_like = stdx::is_specialization_of_v, optional> or stdx::is_specialization_of_v, std::optional>; @@ -328,8 +325,7 @@ template std::optional; } // namespace detail -template )>> +template constexpr auto transform(F &&f, Ts &&...ts) { using func_t = stdx::remove_cvref_t; using R = std::invoke_result_t< @@ -345,5 +341,3 @@ constexpr auto transform(F &&f, Ts &&...ts) { } } // namespace v1 } // namespace stdx - -// NOLINTEND(modernize-use-constraints) diff --git a/include/stdx/rollover.hpp b/include/stdx/rollover.hpp index 4718b4c..a791df8 100644 --- a/include/stdx/rollover.hpp +++ b/include/stdx/rollover.hpp @@ -13,15 +13,11 @@ template struct rollover_t { using underlying_t = T; constexpr rollover_t() = default; - // NOLINTBEGIN(modernize-use-constraints) - template >> + template U> constexpr explicit rollover_t(U u) : value{static_cast(u)} {} - template >> + template U> constexpr explicit rollover_t(rollover_t u) : rollover_t{static_cast(u)} {} - // NOLINTEND(modernize-use-constraints) [[nodiscard]] constexpr auto as_underlying() const -> underlying_t { return value; diff --git a/include/stdx/span.hpp b/include/stdx/span.hpp index c89b561..da7919c 100644 --- a/include/stdx/span.hpp +++ b/include/stdx/span.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -13,8 +14,6 @@ #include #include -// NOLINTBEGIN(modernize-use-constraints) - namespace stdx { inline namespace v1 { @@ -38,16 +37,14 @@ template class span_base { public: constexpr span_base() = default; - template , int> = 0> - constexpr span_base(It, SizeOrEnd count) - : sz{static_cast(count)} {} - - template , int> = 0> + template constexpr span_base(It first, SizeOrEnd last) : sz{static_cast(std::distance(first, last))} {} + template + constexpr span_base(It, SizeOrEnd count) + : sz{static_cast(count)} {} + [[nodiscard]] constexpr auto size() const noexcept -> std::size_t { return sz; } @@ -85,13 +82,13 @@ class span : public detail::span_base { constexpr span() = default; - template != dynamic_extent, int> = 0> + template + requires(dependent_extent != dynamic_extent) explicit constexpr span(It first, SizeOrEnd) : ptr{stdx::to_address(first)} {} - template == dynamic_extent, int> = 0> + template + requires(dependent_extent == dynamic_extent) constexpr span(It first, SizeOrEnd sore) : base_t{first, sore}, ptr{stdx::to_address(first)} {} @@ -122,27 +119,23 @@ class span : public detail::span_base { "Span extends beyond available storage"); } - template != dynamic_extent, int> = 0> + template + requires(dependent_extent != dynamic_extent) explicit constexpr span(R &&r) : ptr{stdx::to_address(std::begin(std::forward(r)))} {} - template == dynamic_extent, int> = 0> + template + requires(dependent_extent == dynamic_extent) explicit constexpr span(R &&r) : base_t{std::begin(std::forward(r)), std::end(std::forward(r))}, ptr{stdx::to_address(std::begin(std::forward(r)))} {} - template != dynamic_extent and - N == dynamic_extent, - int> = 0> + template + requires(dependent_extent != dynamic_extent and N == dynamic_extent) explicit constexpr span(span const &s) noexcept : ptr{s.data()} {} - template == dynamic_extent or - N != dynamic_extent, - int> = 0> + template + requires(dependent_extent == dynamic_extent or N != dynamic_extent) // NOLINTNEXTLINE(google-explicit-constructor) constexpr span(span const &s) noexcept : base_t{s.data(), s.size()}, ptr{s.data()} {} @@ -254,8 +247,8 @@ template auto as_bytes(span s) noexcept { } } -template , int> = 0> +template + requires(not std::is_const_v) auto as_writable_bytes(span s) noexcept { if constexpr (N == dynamic_extent) { return span{reinterpret_cast(s.data()), s.size_bytes()}; @@ -293,5 +286,3 @@ constexpr auto ct_capacity_v> = detail::ct_capacity_fail>{}; } // namespace v1 } // namespace stdx - -// NOLINTEND(modernize-use-constraints) diff --git a/include/stdx/type_traits.hpp b/include/stdx/type_traits.hpp index 34c3602..09c99ed 100644 --- a/include/stdx/type_traits.hpp +++ b/include/stdx/type_traits.hpp @@ -205,8 +205,8 @@ template constexpr auto try_construct() -> T { } template struct any_t { - // NOLINTNEXTLINE(modernize-use-constraints) - template , int> = 0> + template + requires(not std::is_same_v) // NOLINTNEXTLINE(google-explicit-constructor) constexpr operator U() { return try_construct(); diff --git a/include/stdx/utility.hpp b/include/stdx/utility.hpp index 7ec1995..fd94f8b 100644 --- a/include/stdx/utility.hpp +++ b/include/stdx/utility.hpp @@ -10,8 +10,6 @@ #include #include -// NOLINTBEGIN(modernize-use-constraints) - namespace stdx { inline namespace v1 { @@ -126,15 +124,13 @@ template template using forward_like_t = decltype(stdx::forward_like(std::declval())); -template , int> = 0> -[[nodiscard]] constexpr auto as_unsigned(T t) { +template [[nodiscard]] constexpr auto as_unsigned(T t) { static_assert(not std::is_same_v, "as_unsigned is not applicable to bool"); return static_cast>(t); } -template , int> = 0> -[[nodiscard]] constexpr auto as_signed(T t) { +template [[nodiscard]] constexpr auto as_signed(T t) { static_assert(not std::is_same_v, "as_signed is not applicable to bool"); return static_cast>(t); @@ -205,15 +201,13 @@ struct from_any { struct value_marker {}; struct type_val { - template >> + template U> friend constexpr auto operator+(T t, U const &) -> T { return t; } friend constexpr auto operator+(type_val const &f) -> type_val { return f; } - template >> + template U> friend constexpr auto operator-(T, U const &) -> value_marker { return {}; } @@ -402,4 +396,3 @@ auto cx_detect(auto f) { #endif // NOLINTEND(cppcoreguidelines-macro-usage) -// NOLINTEND(modernize-use-constraints)