Skip to content

Instantly share code, notes, and snippets.

View robertshepherdcpp's full-sized avatar
💻
Programming in C++

Robert Shepherd robertshepherdcpp

💻
Programming in C++
View GitHub Profile
#include <cstddef>
#include <iostream>
#include <utility>
namespace mlib {
template <auto N>
constexpr auto get_nth_element(auto... args) {
return [&]<std::size_t... Indexes>(std::index_sequence<Indexes...>) {
return [](decltype((void*)Indexes)... DontCare, auto* arg,
auto*... DontCareEither) { return *arg; }(&args...);
#include<iostream>
template<auto A, auto B, auto first_, auto second_, typename to_compare>
struct inline_if
{
constexpr auto operator()()
{
if constexpr(to_compare{}.template operation<A, B>())
{
return first_;
@robertshepherdcpp
robertshepherdcpp / example_decreasing_tuple.cpp
Created December 21, 2022 13:13
How to use the decreasing tuple idiom.
#include<tector.hpp>
#include<iostream>
int main()
{
tector<int, int, int, int> t{3, 5, 4, 1};
t.remove_first(); // so now we just have the elements 5, 4, 1
// Now we can call remove_first again like this:
t.remove_first(); // Now we have the elements 4, 1
@robertshepherdcpp
robertshepherdcpp / DecreasingTuple.cpp
Created December 17, 2022 17:38
A cool new idiom for a decreasing tuple
template<typename T, typename... Ts>
struct Tuple
{
T first;
Tuple<Ts...> second{};
bool first_removed = false;
auto remove_first()
{
if(first_removed == false)