Skip to content

Standard Meta-Template Library - An experiment in C++ template meta-programming

Notifications You must be signed in to change notification settings

mikenz1000/smtl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Standard Meta-Template Library

This project is an experiment in implementing STL and LINQ concepts using template metaprogramming. The tests folder contains cpp files that show all the templates being used. Selected highlights are...

Vector

vector.h defines a simple templated vector where the variadic template arguments are the elements of the vector

#include "smtl/vector.h"
using smtl;
vector<1,2,3> v;

Template metaprogramming QSort

See qsort.h for a fairly readable template that will sort a templated vector using the qsort algorithm. It uses concat.h to concatenate sub-vectors during computation and where.h to filter the left and right sub-vectors on basis of elements being less-than or greater-than-or-equal the pivot.

#include <smtl/qsort.h>
using namespace smtl;

static_assert(std::is_same<::smtl::qsort<vector<9,4,5,3,2,6,7,1,8>>::value, 
                           vector<1,2,3,4,5,6,7,8,9>>::value);

Reverse a vector template list

See reverse.h for a template that will reverse the arguments of a templated vector.

#include <assert.h>
#include <smtl/reverse.h>
using namespace smtl;

static_assert(std::is_same<vector<1,2,3>,reverse<vector<3,2,1>>::value>::value);

Multiply elements in a templated vector

select.h provides a template that will apply an operation to the arguments of a templated vector. This example also uses range.h to generate a vector representing a sequence of ints.

#include <smtl/select.h>
#include <smtl/math.h>
#include <smtl/range.h>
#include <type_traits>

using namespace smtl;

static_assert(std::is_same<
    vector<2,4,6>,
    select<range<1,4>::value, multiply<2>>::value
    >::value);

About

Standard Meta-Template Library - An experiment in C++ template meta-programming

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published