Giter VIP home page Giter VIP logo

hyperion_mpl's Introduction

hyperion::mpl

XMake CMake

hyperion::mpl is a C++20 metaprogramming library focused on making metaprogramming simple and easy. With hyperion::mpl, metaprogramming almost as easy as typical application code: you can metaprogram using (relatively) normal variables, values, and functions, in an ergonomic and functional style, instead of the bloat and complexity of the struct templates, partial specializations, SFINAE, and other techniques and tricks typically used in C++ metaprogramming.

Quick Start

See the Quick Start Guide for how to get started using hyperion::mpl.

Documentation

You can also find the rest of the project documentation here

Example

After following the Quick Start Guide, you'll be able to use hyperion::mpl in your project. A basic example of what you can do with hyperion::mpl is below:

#include <hyperion/mpl/list.h>
#include <hyperion/mpl/type.h>
#include <hyperion/mpl/value.h>

#include <concepts>
#include <ranges>

using namespace hyperion;
using namespace hyperion::mpl;

constexpr auto add_const = [](MetaType auto type) noexcept {
    return type.as_const();
};

constexpr auto list = List<int, double, float>{};
constexpr auto zipped = list.zip(List<u32, usize, i32>{});
constexpr auto constified = zipped.apply(add_const);

static_assert(constified == List<Pair<const int, const u32>,
                                 Pair<const double, const usize>,
                                 Pair<const float, const i32>>{});
static_assert(constified.all_of(is_const));

constexpr auto list2 = List<int, const double, float>{};
// ranges support is implemented for `mpl::List` at all times,
// but usage in practice requires a complete standard library implementation
// for ranges. (i.e. `operator|` isn't particularly useful without the
// `std::ranges::<things>` to go along with it)
constexpr auto ranged
        = list
            | std::ranges::views::filter([](MetaType auto type) { return not type.is_const(); })
            | std::ranges::views::transform([](MetaType auto type) {
                return type.as_lvalue_reference().as_volatile();
            })
            | std::ranges::views::reverse
            | std::ranges::views::drop(1_value);
static_assert(ranged == List<volatile int&>{});

constexpr auto add_one = [](MetaValue auto value) {
    return value + 1_value;
};
constexpr auto times_two = [](MetaValue auto value) {
    return value * 2_value;
};

static_assert(2_value
              .apply(add_one)
              .apply(times_two)
              .apply(add_one) == 7);

constexpr auto val3 = 10;
static_assert(decltype_(val3)
              .apply<std::remove_reference>()
              .apply<std::remove_const>()
              .apply<std::add_rvalue_reference>()
              == decltype_<int&&>());

constexpr auto add_lvalue_reference = [](MetaType auto type) {
    return type.as_lvalue_reference();
};

constexpr auto remove_reference = [](MetaType auto type)
    -> std::remove_reference<typename decltype(type)::type>
{
    return {};
};

static_assert(decltype_<int&&>()
              .apply(remove_reference)
              .apply(add_const)
              .apply(add_lvalue_reference)
              == decltype_<const int&>());

constexpr auto val1 = Value<4>{};
constexpr auto val2 = Value<2>{};
constexpr auto meaning_of_life = (val1 * 10_value) + val2;
static_assert(meaning_of_life == 42);

Contributing

Feel free to submit issues, pull requests, etc.!
When contributing code, please follow the general style expectations of Hyperion projects:

  • Follow the project .clang-format (except in judicious cases of templates or requires clauses ruining formatting),
  • Use trailing returns types,
  • Use assign-init (e.g. auto var = value;) instead of direct-init (e.g. auto var{value}),
  • By default, prefer simplicity and correctness over performance
  • We try to target Clang/LLVM 15, which doesn't yet support usage of concepts in function definitions occurring after the declaration (for example, defining a function template outside of the class it was declared in). In these cases, revert to using enable_if instead.

License

hyperion::mpl uses the MIT license.

hyperion_mpl's People

Contributors

braxtons12 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

hyperion_mpl's Issues

Hi, just a review from the point of my own personal experience/preference

Hi ๐Ÿ‘‹,

After looking at mpl/list.h

1. header files extension

Why not to use *.hpp for C++ files, especially when utilizing cpp-only feature - templates !?

2. include guards

Why would anybody use C-style header guards in C++20 in the year 2024???

3. horizontal indentation inside namespaces

namespace hyperion::mpl {

    template<typename... TTypes>
    struct List;
    ...
} // namespace hyperion::mpl
  • harms readability (by permanent odd indentation)

4. tests

namespace hyperion::mpl::_test::list {

1703 - 1396 = 307 lines for tests, that can be moved to mpl/tests/test_list.hpp and just be included at the end of mpl/list.hpp (if needed) to declutter things

5. README.md#example

  • Would be nice to separate different tests with comment-headers like: // testing <things>
  • Also feel lack of closer to real usage examples that will show what this library is aiming to simplify/achieve
    • maybe there will appear some with time

Happy to see

  • CMakePresets.json
  • CMakeLists.txt
    • not cucual, but file(GLOB_RECURSE can be used to gather all sources
    • and list(FILTER _SOURCE_FILES EXCLUDE REGEX ".*\\/_.*\\..*") to exclude _<temp_file>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.