This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <numeric> | |
namespace my_numeric { | |
template<std::ranges::range Range, typename T, typename BinaryOp> | |
[[nodiscard]] constexpr T accumulate(Range&& container, BinaryOp&& binop, T&& value) { | |
return std::accumulate(std::ranges::begin(container), std::ranges::end(container), value, binop); | |
} | |
template<std::ranges::range Range, typename T> | |
[[nodiscard]] constexpr T accumulate(Range&& container, T&& value) { | |
return std::accumulate(std::ranges::begin(container), std::ranges::end(container), value, std::plus<>{}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename Function> | |
class finally_t { | |
public: | |
finally_t(Function&& fnc) :func{std::move(fnc)} {} | |
~finally_t() { func(); } | |
private: | |
Function func; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T,typename parametre,template<typename> class...Skills> | |
class __declspec(empty_bases) NamedType : public Skills<NamedType<T,parametre,Skills...>>... { | |
public: | |
constexpr NamedType(T const& elem):_value {elem} {} | |
template<typename T_=T>requires(!std::is_reference_v<T_>) | |
constexpr NamedType(T&& elem):_value {std::move(elem)} {} | |
T& get() { return _value; } | |
T const& get() const { return _value; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T> | |
concept Printable = requires (T val) { std::cout<<val; }; | |
template<char seperator,typename...Type> | |
requires (Printable<Type>,...) | |
void pack_print(Type&&...values) { | |
((std::cout<<std::forward<Type>(values)<<seperator),...); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <string_view> | |
template<typename...T> | |
concept all_strings = std::is_same_v<T...,std::string> || std::is_same_v<T...,std::string_view>; | |
constexpr auto concat_strings(all_strings auto&&...values_) -> std::string { | |
const auto length_ {(std::size_t{0}+...+values_.size())}; | |
auto created_string {std::string{}}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Non algorithm include version | |
template<typename...Ranges> | |
requires(std::ranges::range<Ranges>,...) | |
void braced_print(Ranges&&...ranges) { | |
using namespace std::literals; | |
[&ranges...] { | |
([] <typename T>(T&& range) { | |
for(std::cout<<"( "sv; auto& element:range) { | |
std::cout<<element<<' '; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[nodiscard]] /*constexpr*/ int make_change(int current_money) { | |
int change_amount {0}; | |
auto generate_change {[¤t_money,&change_amount](int bill_size) { | |
change_amount += current_money/bill_size; | |
current_money %= bill_size; | |
}}; | |
std::ranges::for_each(std::array {500,100,25,10,5,1},generate_change); | |
return change_amount+=current_money; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[[nodiscard]] std::vector<std::size_t> solve_nonogram(std::ranges::contiguous_range auto&& problem) { | |
namespace ranges = std::ranges; | |
std::vector<std::size_t> streaks {}; | |
streaks.reserve(problem.size()); | |
ranges::split_view splits {problem,0}; | |
auto add_size {[&streaks](auto&& range) { | |
if (const auto size {ranges::distance(range)}; size!=0) { |