mirror of
https://github.com/Light-City/CPlusPlusThings.git
synced 2026-07-07 22:06:08 +08:00
support bazel complie this project and format code.
This commit is contained in:
28
learn_class/modern_cpp_30/SFINAE/sfinae paper/hana.cpp
Normal file
28
learn_class/modern_cpp_30/SFINAE/sfinae paper/hana.cpp
Normal file
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Created by light on 20-1-6.
|
||||
//
|
||||
// https://www.boost.org/doc/libs/1_62_0/libs/hana/doc/html/structboost_1_1hana_1_1type.html#a2d2e7e08e284f7e0bd1bd9c3ad0e0a2b
|
||||
#include <boost/hana.hpp>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace hana = boost::hana;
|
||||
|
||||
|
||||
int main() {
|
||||
// 检查成员
|
||||
struct Person {
|
||||
std::string name;
|
||||
};
|
||||
auto has_name = hana::is_valid([](auto &&p) -> decltype(p.name) {});
|
||||
|
||||
Person joe{"Joe"};
|
||||
static_assert(has_name(joe), "");
|
||||
static_assert(!has_name(1), "");
|
||||
// 检查嵌套类型
|
||||
auto has_value_type = hana::is_valid([](auto t) -> hana::type<typename decltype(t)::type::value_type> {});
|
||||
static_assert(has_value_type(hana::type_c<std::vector<int>>), "");
|
||||
static_assert(!has_value_type(hana::type_c<Person>), "");
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user