tuples
所属分类:C/C++工具库
开发工具:CMake
文件大小:0KB
下载次数:0
上传日期:2016-04-15 03:35:20
上 传 者:
sh-1993
说明: 公共域中作为类型向量的元组的C++1z模板元编程库
(C++1z template metaprogramming library for tuples as type vectors, in the public domain)
文件列表:
tuples-tuples/ (0, 2016-04-12)
tuples-tuples/.travis.yml (606, 2016-04-12)
tuples-tuples/CMakeLists.txt (907, 2016-04-12)
tuples-tuples/LICENSE (1210, 2016-04-12)
tuples-tuples/cmake/ (0, 2016-04-12)
tuples-tuples/cmake/FindLB/ (0, 2016-04-12)
tuples-tuples/cmake/FindLB/tuples.cmake (9417, 2016-04-12)
tuples-tuples/src/ (0, 2016-04-12)
tuples-tuples/src/multi_assert.hpp (879, 2016-04-12)
tuples-tuples/src/tuple.hpp (377, 2016-04-12)
tuples-tuples/src/tuple_contains.hpp (1118, 2016-04-12)
tuples-tuples/src/tuple_forward.hpp (833, 2016-04-12)
tuples-tuples/src/tuple_prune.hpp (1060, 2016-04-12)
tuples-tuples/src/tuple_template_forward.hpp (769, 2016-04-12)
tuples-tuples/src/tuple_type_cat.hpp (723, 2016-04-12)
tuples-tuples/test/ (0, 2016-04-12)
tuples-tuples/test/CMakeLists.txt (371, 2016-04-12)
tuples-tuples/test/multi_assert.cpp (377, 2016-04-12)
tuples-tuples/test/tuple_contains.cpp (285, 2016-04-12)
tuples-tuples/test/tuple_forward.cpp (420, 2016-04-12)
tuples-tuples/test/tuple_prune.cpp (279, 2016-04-12)
tuples-tuples/test/tuple_template_forward.cpp (470, 2016-04-12)
tuples-tuples/test/tuple_type_cat.cpp (269, 2016-04-12)
tuples [![travis](https://travis-ci.org/LB--/tuples.svg?branch=tuples)](https://travis-ci.org/LB--/tuples)
======
Tuples are useful for acting as arrays of types in template metaprogramming, often called type vectors. This library has boilerplate code for dealing with tuples at compile-time and also some utility functions.
**Some support for C++1z is required.**
## Usage
### CMake
From the `cmake` directory, copy the `FindLB` directory to a place in your `CMAKE_MODULE_PATH`.
Then, add `find_package(LB/tuples 1 EXACT REQUIRED)` to your CMake script.
You may need to set the CMake variable `LB/tuples_ROOT` if you installed to a nonstandard location.
Finally, link to the `LB::tuples` imported target with `target_link_libraries()`.
### C++
Note that alongside `std::tuple` there is also [`LB::tuples::tuple`](https://github.com/LB--/tuples/blob/tuples/src/tuple.hpp) - the latter does not hold any data whereas the former does.
`std::tuple` does not support `void` or abstract types, whereas `LB::tuples::tuple` does - the latter should be your default.
#### [`tuple_template_forward`](https://github.com/LB--/tuples/blob/tuples/src/tuple_template_forward.hpp)
##### `#include
`
Takes the types stored in an `LB::tuples::tuple` or a `std::tuple` and uses them as template parameters to the given template.
Due to limitations in the C++ language, you cannot forward types to a template that has value template arguments even if they are defaulted - instead, you should create a proxy template in that situation.
For [example](https://github.com/LB--/tuples/blob/tuples/test/tuple_template_forward.cpp), you could use it to convert between `LB::tuples::tuple` and `std::tuple`:
```cpp
//convert LB::tuples::tuple to std::tuple
using t1 = LB::tuples::tuple;
using t2 = LB::tuples::tuple_template_forward_t;
static_assert(std::is_same>{}, "t1 != t2");
//convert std::tuple to LB::tuples::tuple
using t3 = std::tuple;
using t4 = LB::tuples::tuple_template_forward_t;
static_assert(std::is_same>{}, "t3 != t4");
```
#### [`tuple_forward`](https://github.com/LB--/tuples/blob/tuples/src/tuple_forward.hpp)
##### `#include `
Takes the values in a `std::tuple` and calls a function with them.
See [`std::apply`](http://en.cppreference.com/w/cpp/utility/apply) - `tuple_forward` is an implementation for cases when `std::apply` is not available.
If you have access to `std::apply` and/or `std::invoke`, please use them instead as they are more robust.
When C++17 is finalized and major compilers and standard library implementations have support for `std::apply`, this function will be deprecated.
For obvious reasons, `LB::tuples::tuple` is not supported.
[Example](https://github.com/LB--/tuples/blob/tuples/test/tuple_forward.cpp):
```cpp
static constexpr auto t1 = std::make_tuple(1, 1);
static constexpr auto t2 = std::make_tuple(1, 2);
static_assert(LB::tuples::tuple_forward(std::equal_to{}, t1), "t1 doesn't contain the same value twice");
static_assert(!LB::tuples::tuple_forward(std::equal_to{}, t2), "t2 contains the same value twice");
```
#### [`tuple_type_cat`](https://github.com/LB--/tuples/blob/tuples/src/tuple_type_cat.hpp)
##### `#include `
Concatenates the types in zero or more `LB::tuples::tuple`s in left-to-right order.
`std::tuple` is not supported.
[Example](https://github.com/LB--/tuples/blob/tuples/test/tuple_type_cat.cpp):
```cpp
using t1 = LB::tuples::tuple;
using t2 = LB::tuples::tuple;
using t3 = typename LB::tuples::tuple_type_cat_t;
static_assert(std::is_same>{}, "t1 + t2 != t3");
```
#### [`tuple_contains`](https://github.com/LB--/tuples/blob/tuples/src/tuple_contains.hpp)
##### `#include `
Checks if an `LB::tuples::tuple` contains the given type.
`std::tuple` is not supported.
[Example](https://github.com/LB--/tuples/blob/tuples/test/tuple_contains.cpp):
```cpp
using t1 = LB::tuples::tuple;
using t2 = LB::tuples::tuple;
static_assert(!LB::tuples::tuple_contains{}, "t1 contains float");
static_assert(LB::tuples::tuple_contains_v, "t2 doesn't contain float");
```
#### [`tuple_prune`](https://github.com/LB--/tuples/blob/tuples/src/tuple_prune.hpp)
##### `#include `
Takes an `LB::tuples::tuple` and removes duplicate types without rearranging the order of the types.
`std::tuple` is not supported.
[Example](https://github.com/LB--/tuples/blob/tuples/test/tuple_prune.cpp):
```cpp
using pruned_t = LB::tuples::tuple_prune_t
<
LB::tuples::tuple
>;
static_assert(std::is_same>{}, "tuple_prune is broken");
```
#### [`multi_assert`](https://github.com/LB--/tuples/blob/tuples/src/multi_assert.hpp)
##### `#include `
Given a template that takes zero or more template arguments and yields a `value` member, takes all the given `LB::tuples::tuple`s and/or `std::tuple`s and forwards their contents to the given template individually.
The resulting `value` is all the intermediate `value`s combined with `&&`.
In other words, asserts that multiple tuples satisfy a requirement.
[Example](https://github.com/LB--/tuples/blob/tuples/test/multi_assert.cpp):
```cpp
using t1 = LB::tuples::tuple;
using t2 = LB::tuples::tuple;
using t3 = LB::tuples::tuple;
static_assert(LB::tuples::multi_assert{}, "t1 or t2 isn't homogeneous");
static_assert(!LB::tuples::multi_assert_v, "t1, t2 and t3 are homogeneous");
```
近期下载者:
相关文件:
收藏者: