GithubHelp home page GithubHelp logo

libctmap's Introduction

libctmap

Badge LICENSE Repo Size Code Size

一个编译时的 c++ map

构建

库本身不需要先编译。可以编译一下自带测试代码:

cd <project dir>
mkdir build
cd build
cmake -DBUILD_TEST=ON ..

编译成功即通过测试。

用法

在 CMakeLists.txt 中添加如下代码:

add_subdirectory(libctmap_project_dir)
target_link_libraries(your_project PRIVATE libctmap)

编译器最低需要支持 C++11,也可通过定义宏 CT_ENABLE_CXX_17 开启 C++17 来提供一些新的接口。例如:

#define CT_ENABLE_CXX_17
#include <ctmap.hpp>

接口

后面的代码假设已经存在这样的环境:

#define CT_ENABLE_CXX_17
#include <ctmap.hpp>

struct k1 {}; struct k2 {}; struct k3 {}; struct k4 {};
struct v1 {}; struct v2 {}; struct v3 {}; using v4 = ct::i32<4>;

constructor

using m1 = ct::map<>::insert_v<k1, v1>::insert_v<k2, v2>;
using m2 = ct::map_from_list_t<k1, v1, k2, v2>;
static_assert(m1::equal<m1, m2>::value, "");

size

using m2 = ct::map_from_list_t<k1, v1, k2, v2>;
static_assert(m2::size == 2, "");

contains

using m2 = ct::map_from_list_t<k1, v1, k2, v2>;
static_assert(m2::contains<k2>::value, "");
static_assert(!m2::contains<k3>::value, "");
static_assert(m2::contains_v<k2>);     // c++17
static_assert(!m2::contains_v<k3>);    // c++17

equal

using m1 = ct::map_from_list_t<k2, v2, k1, v1>;
using m2 = ct::map_from_list_t<k1, v1, k2, v2>;
static_assert(m1::equal<m2>::value, "");
static_assert(!m1::equal<m2>::value, "");
static_assert(m1::equal_v<m2>);     // c++17
static_assert(!m1::equal_v<m2>);    // c++17

at

using m = ct::map_from_list_t<k1, v1, k4, v4>;
static_assert(std::is_same<m::at_t<k1>, v1>::value, "");
static_assert(std::is_same<m::at_t<k4>, v4>::value, "");
static_assert(m::at<k4>::value == v4::value, "");
static_assert(m::at_v<k4> == v4::value);    // c++17

erase

using m1 = ct::map_from_list_t<k1, v1, k2, v2, k3, v3>;
using m2 = ct::map_from_list_t<k1, v1, k3, v3>;
using t = m1::erase_t<k2>;
static_assert(t::equal<m2>::value, "");

merge

using m1 = ct::map_from_list_t<k1, v1, k3, v3>;
using m2 = ct::map_from_list_t<k2, v2, k4, v4>;
using m3 = ct::map_from_list_t<k1, v1, k2, v2, k3, v3, k4, v4>;
using t = m1::merge_t<m2>;
static_assert(t::equal<m3>::value, "");

许可证

反 996 许可证版本 1.0

libctmap's People

Contributors

ghtz08 avatar

Stargazers

Hypen Zou avatar

Watchers

 avatar

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.