Skip to content

Instantly share code, notes, and snippets.

template<typename T, template<typename...> class C, typename... Args>
C<T, Args...> in (C<T, Args...>& input, auto func)
{
C<T, Args...> items;
for (auto inp=input.begin(); inp!=input.end(); inp++) (void)items.insert(items.end(),func(*inp));
return items;
}
#include <vector>
#include <deque>
#include <map>
#include <set>
#include <list>
#include <string>
using namespace std;
int main()
{
#include <array>
template <typename T, size_t S>
class into : public std::array<T,S>
{
public:
into (std::array<T,S>& input, auto func)
{
for (size_t i=0; i<this->size(); i++)
{
set nums = {1,2,3,4};
auto result = in(nums, [](auto x) { return x*x; });
set nums = {1,2,3,4};
auto result = in(nums, each(x, x*x)); // insert all elements multiplied by themselves
auto result = in(nums, each(x, (x>2)?x*x:x)); // insert all elements but only multiply those that fulfill the condition
auto result = in(nums, only(x, x<2, x*x)); // insert only the elements that fulfill the condition
auto result = in(nums, only(x, x<4 && cout<<x, x*x)); // insert and print only the elements that fulfill the condition (prints: 123)
nums = [1,2,3,4]
result = [x*x for x in nums]
#include <deque>
template <class T>
class table
{
public:
table<T> select (const auto& where)
{
table results;
for(auto t : rows) if (where(t)) results.insert(t);
#include <iostream>
int e = 10;
int *p = &e;
const int *q = &e;
void reset_none (const int * const & ptr) { static int a = 11; /* (*ptr=a); (ptr=&a); */ }
void reset_value_only (int * const & ptr) { static int a = 12; (*ptr=a); /* (ptr=&a) */ }
void reset_pointer_only (const int * & ptr) { static int a = 13; /* (*ptr=a); */ ptr=&a; }
int main()
{
reset_none(p);
// SncSensor| Arduino Board
// UCC = 5v on the POWER row
// TRIGGER = -9 pin
// ECHO = -10 pin
// GND = any GND
int trigPin = 9;
int echoPin = 10;
int led1 = 13;
#include <iostream>
#include <list>
#include <cstdlib>
#include <cstring>
#include <cassert>
namespace owl {
class memory
{
public: