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
8 changes: 4 additions & 4 deletions cth/incl/cth/algorithm/alg_utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
namespace cth::ranges {
struct piped_fn {};
template<class T, class Fn> requires std::derived_from<std::remove_cvref_t<Fn>, piped_fn>
cxpr declauto operator|(T&& left, Fn&& fn) {
constexpr decltype(auto) operator|(T&& left, Fn&& fn) {
return std::forward<Fn>(fn)(std::forward<T>(left));
}
} // namespace cth::ranges
Expand All @@ -29,12 +29,12 @@ struct pipe_call_closure : piped_fn {
);

template<class... CArgs> requires(std::same_as<std::decay_t<CArgs>, FnArgs> && ...)
explicit cxpr pipe_call_closure(CArgs&&... args) : _args{std::forward<CArgs>(args)...} {}
explicit constexpr pipe_call_closure(CArgs&&... args) : _args{std::forward<CArgs>(args)...} {}

template<class T, class Me> requires std::invocable<Fn, T, FnArgs...>
cxpr declauto operator()(this Me&& me, T&& arg) {
constexpr decltype(auto) operator()(this Me&& me, T&& arg) {
return std::apply(
[&arg]<class... Args>(this auto&&, Args&&... args) -> declauto {
[&arg]<class... Args>(this auto&&, Args&&... args) -> decltype(auto) {
return Fn{}(std::forward<T>(arg), std::forward<Args>(args)...);
},
std::forward<Me>(me)._args
Expand Down
32 changes: 16 additions & 16 deletions cth/incl/cth/algorithm/views.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
namespace cth::views {
struct to_ptr_range_fn : cth::ranges::piped_fn {
template<std::ranges::viewable_range Rng> requires std::is_lvalue_reference_v<std::ranges::range_reference_t<Rng>>
cxpr auto operator()(Rng&& rng) const {
constexpr auto operator()(Rng&& rng) const {
return std::views::transform(std::forward<Rng>(rng), [](auto& element) { return &element; });
}
};

inline cxpr to_ptr_range_fn to_ptr_range;
inline constexpr to_ptr_range_fn to_ptr_range;

struct split_into_fn {
/**
Expand All @@ -28,7 +28,7 @@ struct split_into_fn {
* @return view of
*/
template<std::ranges::sized_range Rng>
cxpr auto operator()(Rng&& rng, std::ranges::range_difference_t<Rng> const max_chunks) const {
constexpr auto operator()(Rng&& rng, std::ranges::range_difference_t<Rng> const max_chunks) const {
assert(max_chunks > 0 && "cannot chunk into <= 0 chunks");

auto const rngSize = std::ranges::size(rng);
Expand All @@ -38,7 +38,7 @@ struct split_into_fn {
}

template<class Fn, class T> requires std::constructible_from<std::decay_t<T>, T>
cxpr auto operator()(this Fn&&, T&& chunks) {
constexpr auto operator()(this Fn&&, T&& chunks) {
return ranges::pipe_call_closure<
std::remove_cvref_t<Fn>, std::decay_t<T>
>{std::forward<T>(chunks)};
Expand All @@ -48,35 +48,35 @@ struct split_into_fn {
/**
* splits a range into <= n chunks
*/
inline cxpr split_into_fn split_into;
inline constexpr split_into_fn split_into;

struct drop_stride_fn {
template<std::ranges::viewable_range Rng>
cxpr auto operator()(
constexpr auto operator()(
Rng&& rng,
std::ranges::range_difference_t<Rng> const drop,
std::ranges::range_difference_t<Rng> const stride
) const { return std::views::stride(std::views::drop(std::forward<Rng>(rng), drop), stride); }

template<class Fn, class T, class U> requires(std::constructible_from<std::decay_t<T>, T> && std::constructible_from
<std::decay_t<U>, U>)
cxpr auto operator()(this Fn&&, T&& drop, U&& stride) {
constexpr auto operator()(this Fn&&, T&& drop, U&& stride) {
return ranges::pipe_call_closure<std::remove_cvref_t<Fn>, std::decay_t<T>, std::decay_t<U>>{
std::forward<T>(drop),
std::forward<U>(stride)
};
}
};

inline cxpr drop_stride_fn drop_stride;
inline constexpr drop_stride_fn drop_stride;

struct transform_call_fn {
template<class Rng>
using range_value_t = std::ranges::range_value_t<Rng>;

template<std::ranges::range Rng, class Call, class... Args> requires(std::invocable<Call, std::ranges::range_value_t
<Rng>, Args...>)
cxpr auto operator()(Rng&& rng, Call&& call, Args&&... args) const {
constexpr auto operator()(Rng&& rng, Call&& call, Args&&... args) const {
return std::views::transform(
std::forward<Rng>(rng),
[&call, &args...] < class T >(T&& element) {
Expand All @@ -90,15 +90,15 @@ struct transform_call_fn {
}

template<class Call, class... Args, class Fn> requires(!std::ranges::range<Call>)
cxpr auto operator()(this Fn&&, Call&& call, Args&&... args) {
constexpr auto operator()(this Fn&&, Call&& call, Args&&... args) {
return ranges::pipe_call_closure<std::remove_cvref_t<Fn>, std::decay_t<Call>, std::decay_t<Args>...>{
std::forward<Call>(call),
std::forward<Args>(args)...
};
}
};

inline cxpr transform_call_fn transform_call;
inline constexpr transform_call_fn transform_call;
}

namespace cth::views {
Expand All @@ -121,15 +121,15 @@ struct format_fn {
* @return formattable object
*/
template<std::ranges::viewable_range Rng>
[[nodiscard]] cxpr auto operator()(
[[nodiscard]] constexpr auto operator()(
Rng&& rng,
std::string_view sep,
std::string_view pre = "",
std::string_view post = ""
) const { return format_view{std::views::all(std::forward<Rng>(rng)), sep, pre, post}; }

template<class Me>
[[nodiscard]] cxpr auto operator()(
[[nodiscard]] constexpr auto operator()(
this Me&&,
std::string_view sep,
std::string_view pre = "",
Expand All @@ -149,17 +149,17 @@ struct format_fn {

};

inline cxpr format_fn format;
inline constexpr format_fn format;
}

template<class Rng>
struct std::formatter<cth::views::format_view<Rng>> {
using value_type = std::ranges::range_value_t<Rng>;

[[nodiscard]] cxpr auto parse(std::format_parse_context& ctx) { return _formatter.parse(ctx); }
[[nodiscard]] constexpr auto parse(std::format_parse_context& ctx) { return _formatter.parse(ctx); }

template<typename FormatContext>
[[nodiscard]] cxpr auto format(
[[nodiscard]] constexpr auto format(
cth::views::format_view<Rng>& obj,
FormatContext& ctx
) const {
Expand Down
20 changes: 10 additions & 10 deletions cth/incl/cth/exception.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ enum Severity {
CRITICAL,
SEVERITY_SIZE,
};
[[nodiscard]] cxpr std::string_view to_string(Severity sev) {
[[nodiscard]] constexpr std::string_view to_string(Severity sev) {
switch(sev) {
// NOLINT(clang-diagnostic-switch-enum)
case LOG: return "LOG";
Expand Down Expand Up @@ -59,7 +59,7 @@ struct std::formatter<cth::except::Severity> {
namespace cth::except {
class default_exception : public std::exception {
template<class S>
cxpr S& addNoCpy(this S& s, std::string_view msg) noexcept {
constexpr S& addNoCpy(this S& s, std::string_view msg) noexcept {
if(s._details.empty())
s._details = "DETAILS:\n";
s._details += std::format("\t{}\n", msg);
Expand All @@ -82,10 +82,10 @@ class default_exception : public std::exception {
~default_exception() override = default;

template<class S>
cxpr declauto add(this S&& self, std::string_view msg) noexcept { return self.addNoCpy(msg); }
constexpr decltype(auto) add(this S&& self, std::string_view msg) noexcept { return self.addNoCpy(msg); }

template<class S, typename... Args> requires(sizeof...(Args) > 0u)
cxpr declauto add(this S& self, std::format_string<Args...> f_str, Args&&... types) noexcept {
constexpr decltype(auto) add(this S& self, std::format_string<Args...> f_str, Args&&... types) noexcept {
return self.addNoCpy(std::format(f_str, std::forward<Args>(types)...));
}

Expand Down Expand Up @@ -153,14 +153,14 @@ class default_exception : public std::exception {
std::string _what;

public:
[[nodiscard]] cxpr Severity severity() const noexcept { return _severity; }
[[nodiscard]] cxpr std::string_view details() const noexcept { return _details; }
[[nodiscard]] cxpr std::string_view msg() const noexcept { return _msg; }
[[nodiscard]] constexpr Severity severity() const noexcept { return _severity; }
[[nodiscard]] constexpr std::string_view details() const noexcept { return _details; }
[[nodiscard]] constexpr std::string_view msg() const noexcept { return _msg; }

[[nodiscard]] cxpr std::stacktrace const& stacktrace() const noexcept { return _trace; }
[[nodiscard]] cxpr std::source_location const& location() const noexcept { return _sourceLocation; }
[[nodiscard]] constexpr std::stacktrace const& stacktrace() const noexcept { return _trace; }
[[nodiscard]] constexpr std::source_location const& location() const noexcept { return _sourceLocation; }

[[nodiscard]] cxpr char const* what() const noexcept override { return _what.c_str(); }
[[nodiscard]] constexpr char const* what() const noexcept override { return _what.c_str(); }

default_exception(default_exception const& other) noexcept = default;
default_exception(default_exception&& other) noexcept = default;
Expand Down
4 changes: 2 additions & 2 deletions cth/incl/cth/hash/hash_aggregates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace cth::hash {
template<mta::aggregate T>
cxpr size_t hash_aggregate(T const& t) {
constexpr size_t hash_aggregate(T const& t) {
return std::apply(
[] < class... Args >(Args&&... args) { return hash::combine(std::forward<Args>(args)...); },
boost::pfr::structure_tie(t)
Expand All @@ -19,5 +19,5 @@ cxpr size_t hash_aggregate(T const& t) {
#define CTH_HASH_AGGREGATE(type) \
template<> \
struct std::hash<type> { \
cxpr size_t operator()(type const& x) const noexcept { return cth::hash::hash_aggregate(x); } \
constexpr size_t operator()(type const& x) const noexcept { return cth::hash::hash_aggregate(x); } \
};
6 changes: 3 additions & 3 deletions cth/incl/cth/hash/hash_general.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@
namespace cth::hash {
namespace dev {
template<class T>
cxpr size_t& combine(size_t& seed, T const& v) {
constexpr size_t& combine(size_t& seed, T const& v) {
// from: https://stackoverflow.com/a/57595105
return seed ^= std::hash<T>{}(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
}

template<class... Args>
cxpr size_t combine(Args&&... args) {
constexpr size_t combine(Args&&... args) {
size_t seed = 0;

(dev::combine(seed, std::forward<Args>(args)), ...);
return seed;
}

template<class Rng> requires(std::ranges::range<Rng>)
cxpr size_t rng(Rng&& rng) {
constexpr size_t rng(Rng&& rng) {
size_t seed = 0;
for(auto const& v : std::forward<Rng>(rng))
dev::combine(seed, v);
Expand Down
2 changes: 1 addition & 1 deletion cth/incl/cth/io/console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ template<std::ranges::viewable_range Rng>

namespace cth::io::dev {

inline cxpr size_t MAX_STACK_SIZE = 16;
inline constexpr size_t MAX_STACK_SIZE = 16;

enum Cursor_Ids {
// cursor codes
Expand Down
10 changes: 5 additions & 5 deletions cth/incl/cth/io/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#include <ios>

namespace cth::io::file {
cxpr uintmax_t BYTE = 1;
cxpr uintmax_t KB = BYTE * 1024;
cxpr uintmax_t MB = KB * 1024;
cxpr uintmax_t GB = MB * 1024;
constexpr uintmax_t BYTE = 1;
constexpr uintmax_t KB = BYTE * 1024;
constexpr uintmax_t MB = KB * 1024;
constexpr uintmax_t GB = MB * 1024;

template<uintmax_t Divisor>
uintmax_t size_in(std::filesystem::path const& path) {
Expand All @@ -20,7 +20,7 @@ uintmax_t size_in(std::filesystem::path const& path) {
return file_size(path) / Divisor;
}

cxpr size_t DEFAULT_CHOP_BUFFER_SIZE = 0xfff;
constexpr size_t DEFAULT_CHOP_BUFFER_SIZE = 0xfff;

template<class D, size_t Buffer = DEFAULT_CHOP_BUFFER_SIZE>
std::vector<std::string> chop(std::filesystem::path const& path, D delimiter) {
Expand Down
2 changes: 1 addition & 1 deletion cth/incl/cth/io/keybd/keys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ consteval auto keys_size() { return static_cast<size_t>(Key::ENUM_LAST_VALUE) +
/**
* converts the Key to UTF-8 string symbol
*/
cxpr std::string_view to_utf8_string(Key key) {
constexpr std::string_view to_utf8_string(Key key) {
switch(key) {
// Alphabetical keys
case Key::A: return "A";
Expand Down
4 changes: 2 additions & 2 deletions cth/incl/cth/io/log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ inline bool colored = true;
inline io::col_stream logStream{std::cerr}; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
inline std::mutex logMtx; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)

cxpr io::TextColor text_color(cth::except::Severity severity) {
constexpr io::TextColor text_color(cth::except::Severity severity) {
switch(severity) {
case cth::except::LOG: return io::TextColor::WHITE;
case cth::except::Severity::INFO: return io::TextColor::DARK_CYAN;
Expand All @@ -39,7 +39,7 @@ cxpr io::TextColor text_color(cth::except::Severity severity) {
}
}

[[nodiscard]] cxpr std::string_view label(cth::except::Severity severity) {
[[nodiscard]] constexpr std::string_view label(cth::except::Severity severity) {
switch(severity) {
case cth::except::Severity::LOG: return "[LOG]";
case cth::except::Severity::INFO: return "[INFO]";
Expand Down
3 changes: 0 additions & 3 deletions cth/incl/cth/macro.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#pragma once
#define cxpr constexpr
#define cval consteval
#define declauto decltype(auto)

#define CPT(concept) \
[] < concept > {}
4 changes: 2 additions & 2 deletions cth/incl/cth/meta/inl/ranges.inl
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
namespace cth::mta {

template<class Rng>
[[nodiscard]] cval size_t dimensions(size_t max) {
[[nodiscard]] consteval size_t dimensions(size_t max) {
return trait_count<Rng, std::ranges::range_value_t>(max);
}

namespace dev {
template<class Rng, size_t D>
cval auto md_range_value() {
consteval auto md_range_value() {
static constexpr auto RANK = mta::dimensions<Rng>(D);

return repeat_trait<RANK, std::ranges::range_value_t, Rng>{};
Expand Down
8 changes: 4 additions & 4 deletions cth/incl/cth/meta/inl/traits.inl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace cth::mta {

namespace dev {
template<class T, template<class> class Trait>
cval size_t trait_count_helper(size_t max, size_t n = 0) {
consteval size_t trait_count_helper(size_t max, size_t n = 0) {
if constexpr(!simple_trait_applicable<T, Trait>)
return n;
else {
Expand All @@ -20,11 +20,11 @@ namespace dev {
}

template<class T, template<class> class Trait>
[[nodiscard]] cval size_t trait_count(size_t max_depth) { return dev::trait_count_helper<T, Trait>(max_depth); }
[[nodiscard]] consteval size_t trait_count(size_t max_depth) { return dev::trait_count_helper<T, Trait>(max_depth); }

namespace dev {
template<class T, auto TCpt, template<class> class Trait>
cval size_t cpt_count(size_t max_depth, size_t n = 0) {
consteval size_t cpt_count(size_t max_depth, size_t n = 0) {
if(n >= max_depth)
return n;

Expand All @@ -43,7 +43,7 @@ namespace dev {
}

template<class T, auto TCpt, template<class> class Trait>
[[nodiscard]] cval size_t cpt_count(size_t max_depth) {
[[nodiscard]] consteval size_t cpt_count(size_t max_depth) {
return dev::cpt_count<T, TCpt, Trait>(max_depth);
}

Expand Down
2 changes: 1 addition & 1 deletion cth/incl/cth/meta/md.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace cth::mta {
* @return std::extents
*/
template<size_t D, auto Extent>
[[nodiscard]] cval auto mdextent() {
[[nodiscard]] consteval auto mdextent() {
return std::apply(
[] < class... Args >(Args... args) {
return std::extents<decltype(Extent), (mta::zero<Args>(), Extent)...>{args...};
Expand Down
Loading
Loading