Skip to content

mbeutel/makeshift

Repository files navigation

makeshift: lightweight metaprogramming for C++

metadata build tests
Language
License
Version
Build Status Azure DevOps tests

makeshift is a C++ library which augments the C++ Standard Library with the following: static range algorithms, constvals, a metadata mechanism, and variant transforms.

Contents

Example usage

// assuming C++23
#include <array>
#include <string>
#include <ranges>
#include <tuple>

#include <makeshift/iomanip.hpp>   // for as_enum()
#include <makeshift/metadata.hpp>
#include <makeshift/string.hpp>    // for enum_to_string()

enum class Boundary
{
    dirichlet,
    periodic
};
constexpr auto reflect(gsl::type_identity<Boundary>)
{
    return std::array{
        std::tuple{ Boundary::dirichlet, "Dirichlet" },
        std::tuple{ Boundary::periodic, "periodic" }
    };
}

int main()
{
    constexpr std::array boundaryValues = makeshift::metadata::values<Boundary>();
    std::string boundaryValueList = boundaryValues
        | std::views::transform(
              [](Boundary b)
              {
                  return makeshift::enum_to_string(b);
              })
        | std::views::join_with(", ")
        | std::ranges::to<std::string>();

    std::cout << "Which kind of boundary to use? (" << boundaryValueList << ")\n";
    Boundary b;
    if (!std::cin >> makeshift::as_enum(b))
    {
        std::cerr << "Invalid input.\n";
        return 1;
    }
    std::cout << "Selected boundary: " << makeshift::as_enum(b) << "\n";
}

License

makeshift uses the Boost Software License.

Dependencies

Installation and use

As CMake package

The recommended way to consume makeshift in your CMake project is to use find_package() and target_link_libraries():

cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
    
find_package(makeshift 4.0 REQUIRED)
    
project(my-program LANGUAGES CXX)
    
add_executable(my-program main.cpp)
target_link_libraries(my-program PRIVATE makeshift::makeshift)

The easiest way to set up the dependencies is to use the Vcpkg package manager. With Vcpkg available, clone the makeshift repository and configure a build directory with CMake:

git clone [email protected]:mbeutel/makeshift.git <makeshift-source-dir>
cd <makeshift-source-dir>
mkdir build
cd build
cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE="<vcpkg-dir>/scripts/buildsystems/vcpkg.cmake" ..

Now, configure your project passing the CMake build directory as a parameter:

cd <my-program-source-dir>
mkdir build
cd build
cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE="<vcpkg-dir>/scripts/buildsystems/vcpkg.cmake" -Dmakeshift_DIR:PATH=<makeshift-source-dir>/build ..
cmake --build .

Version semantics

makeshift follows Semantic Versioning guidelines with regard to its API. We aim to retain full API compatibility and to avoid breaking changes in minor and patch releases.

We do not guarantee to maintain ABI compatibility except in patch releases.

Development happens in the master branch. Versioning semantics apply only to tagged releases: there is no stability guarantee between individual commits in the master branch, that is, anything added since the last tagged release may be renamed, removed, have the semantics changed, etc. without further notice.

A minor-version release will be API-compatible with the previous minor-version release. Thus, once a change is released, it becomes part of the API.

Features

TODO

Reference

TODO:

  • n-ary fixed-size algorithms
    • Arrays and tuples as functors
  • Compile-time programming
    • Compile-time computations as a comonadic pattern
    • Domains of compile-time computations
    • Constvals
    • Constvals as functors
    • Constval normalisation
  • Variants
    • The constval--variant equivalence
    • The expand function
    • Variants as functors
  • Metadata
    • Surrogate reflection: values, members, bases
    • Serialisation
    • The expand function with metadata
    • The struct--tuple continuum
    • Things I can now do with structs
  • Polymorphic value types
    • Compile-time polymorphism
    • Type erasure with the Concept--Model idiom
    • Configuring polymorphic code

About

lightweight metaprogramming in C++

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published