mirror of
https://github.com/BlackMATov/meta.hpp.git
synced 2025-12-16 22:17:02 +07:00
dummy manual sources
This commit is contained in:
@@ -41,11 +41,9 @@ target_compile_options(${PROJECT_NAME}
|
||||
>)
|
||||
|
||||
if(BUILD_AS_STANDALONE)
|
||||
option(BUILD_WITH_UNTESTS "Build with unit tests" ON)
|
||||
if(BUILD_WITH_UNTESTS)
|
||||
enable_testing()
|
||||
add_subdirectory(vendors/doctest)
|
||||
add_subdirectory(vendors/fmtlib)
|
||||
add_subdirectory(manuals)
|
||||
add_subdirectory(untests)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
@@ -37,7 +37,7 @@
|
||||
[meta.hpp][meta] is a header-only library. All you need to do is copy the headers files from `headers` directory into your project and include them:
|
||||
|
||||
```cpp
|
||||
#include "meta.hpp/meta.hpp"
|
||||
#include "meta.hpp/meta_all.hpp"
|
||||
```
|
||||
|
||||
Also, you can add the root repository directory to your [cmake](https://cmake.org) project:
|
||||
|
||||
4
TODO.md
4
TODO.md
@@ -1,6 +1,8 @@
|
||||
# meta.hpp
|
||||
|
||||
- add debug type names;
|
||||
- add type names;
|
||||
- add argument names
|
||||
- add variable and member readonly flags
|
||||
- add meta exception class;
|
||||
- add conversion of nullptr to any pointers;
|
||||
- add conversion of any pointers to void pointer ( identically cv-qualified );
|
||||
|
||||
19
manuals/.clang-tidy
Normal file
19
manuals/.clang-tidy
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
Checks: '-*,
|
||||
|
||||
clang-analyzer-*,
|
||||
|
||||
concurrency-*,
|
||||
|
||||
cppcoreguidelines-*,
|
||||
-cppcoreguidelines-avoid-magic-numbers,
|
||||
-cppcoreguidelines-avoid-non-const-global-variables,
|
||||
-cppcoreguidelines-special-member-functions,
|
||||
|
||||
modernize-*,
|
||||
-modernize-use-nodiscard,
|
||||
-modernize-use-trailing-return-type,
|
||||
|
||||
portability-*,
|
||||
'
|
||||
...
|
||||
38
manuals/CMakeLists.txt
Normal file
38
manuals/CMakeLists.txt
Normal file
@@ -0,0 +1,38 @@
|
||||
project(meta.hpp.manuals)
|
||||
|
||||
#
|
||||
# coverage
|
||||
#
|
||||
|
||||
option(BUILD_WITH_COVERAGE "Build with coverage" OFF)
|
||||
if(BUILD_WITH_COVERAGE AND (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang"))
|
||||
set(COVERAGE_FLAGS "--coverage")
|
||||
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${COVERAGE_FLAGS}")
|
||||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COVERAGE_FLAGS}")
|
||||
set(CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} ${COVERAGE_FLAGS}")
|
||||
endif()
|
||||
|
||||
#
|
||||
# executable
|
||||
#
|
||||
|
||||
file(GLOB_RECURSE MANUALS_SOURCES "*.cpp" "*.hpp")
|
||||
add_executable(${PROJECT_NAME} ${MANUALS_SOURCES})
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE meta.hpp doctest_with_main fmt)
|
||||
|
||||
target_compile_options(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
$<$<CXX_COMPILER_ID:MSVC>:
|
||||
/WX /W4>
|
||||
PRIVATE
|
||||
$<$<CXX_COMPILER_ID:GNU>:
|
||||
-Werror -Wall -Wextra -Wpedantic>
|
||||
PRIVATE
|
||||
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
|
||||
-Werror -Weverything -Wconversion>)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE
|
||||
DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
|
||||
DOCTEST_CONFIG_USE_STD_HEADERS)
|
||||
|
||||
add_test(${PROJECT_NAME} ${PROJECT_NAME})
|
||||
15
manuals/meta_examples/arrays_example.cpp
Normal file
15
manuals/meta_examples/arrays_example.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_manuals.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
}
|
||||
|
||||
TEST_CASE("meta/meta_examples/arrays") {
|
||||
namespace meta = meta_hpp;
|
||||
}
|
||||
15
manuals/meta_examples/classes_example.cpp
Normal file
15
manuals/meta_examples/classes_example.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_manuals.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
}
|
||||
|
||||
TEST_CASE("meta/meta_examples/classes") {
|
||||
namespace meta = meta_hpp;
|
||||
}
|
||||
15
manuals/meta_examples/enums_examples.cpp
Normal file
15
manuals/meta_examples/enums_examples.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_manuals.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
}
|
||||
|
||||
TEST_CASE("meta/meta_examples/enums") {
|
||||
namespace meta = meta_hpp;
|
||||
}
|
||||
15
manuals/meta_examples/functions_example.cpp
Normal file
15
manuals/meta_examples/functions_example.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_manuals.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
}
|
||||
|
||||
TEST_CASE("meta/meta_examples/functions") {
|
||||
namespace meta = meta_hpp;
|
||||
}
|
||||
15
manuals/meta_examples/members_example.cpp
Normal file
15
manuals/meta_examples/members_example.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_manuals.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
}
|
||||
|
||||
TEST_CASE("meta/meta_examples/members") {
|
||||
namespace meta = meta_hpp;
|
||||
}
|
||||
15
manuals/meta_examples/methods_example.cpp
Normal file
15
manuals/meta_examples/methods_example.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_manuals.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
}
|
||||
|
||||
TEST_CASE("meta/meta_examples/methods") {
|
||||
namespace meta = meta_hpp;
|
||||
}
|
||||
15
manuals/meta_examples/numbers_example.cpp
Normal file
15
manuals/meta_examples/numbers_example.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_manuals.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
}
|
||||
|
||||
TEST_CASE("meta/meta_examples/numbers") {
|
||||
namespace meta = meta_hpp;
|
||||
}
|
||||
15
manuals/meta_examples/pointers_example.cpp
Normal file
15
manuals/meta_examples/pointers_example.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_manuals.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
}
|
||||
|
||||
TEST_CASE("meta/meta_examples/pointers") {
|
||||
namespace meta = meta_hpp;
|
||||
}
|
||||
15
manuals/meta_examples/references_example.cpp
Normal file
15
manuals/meta_examples/references_example.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_manuals.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
}
|
||||
|
||||
TEST_CASE("meta/meta_examples/references") {
|
||||
namespace meta = meta_hpp;
|
||||
}
|
||||
15
manuals/meta_examples/variables_example.cpp
Normal file
15
manuals/meta_examples/variables_example.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_manuals.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
}
|
||||
|
||||
TEST_CASE("meta/meta_examples/variables") {
|
||||
namespace meta = meta_hpp;
|
||||
}
|
||||
@@ -4,12 +4,8 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <meta.hpp/meta_all.hpp>
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <numbers>
|
||||
#include <sstream>
|
||||
@@ -18,7 +18,7 @@ endif()
|
||||
|
||||
file(GLOB_RECURSE UNTESTS_SOURCES "*.cpp" "*.hpp")
|
||||
add_executable(${PROJECT_NAME} ${UNTESTS_SOURCES})
|
||||
target_link_libraries(${PROJECT_NAME} meta.hpp doctest_with_main fmt)
|
||||
target_link_libraries(${PROJECT_NAME} PRIVATE meta.hpp doctest_with_main fmt)
|
||||
|
||||
target_compile_options(${PROJECT_NAME}
|
||||
PRIVATE
|
||||
@@ -31,4 +31,8 @@ target_compile_options(${PROJECT_NAME}
|
||||
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
|
||||
-Werror -Weverything -Wconversion>)
|
||||
|
||||
target_compile_definitions(${PROJECT_NAME} PRIVATE
|
||||
DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
|
||||
DOCTEST_CONFIG_USE_STD_HEADERS)
|
||||
|
||||
add_test(${PROJECT_NAME} ${PROJECT_NAME})
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
class shape {
|
||||
public:
|
||||
shape() = default;
|
||||
virtual ~shape() = default;
|
||||
|
||||
virtual double area() const = 0;
|
||||
};
|
||||
|
||||
class circle : public shape {
|
||||
public:
|
||||
explicit circle(double radius)
|
||||
: radius_{radius} {}
|
||||
|
||||
double area() const override {
|
||||
return std::numbers::pi * radius_ * radius_;
|
||||
}
|
||||
|
||||
double radius() const {
|
||||
return radius_;
|
||||
}
|
||||
private:
|
||||
double radius_{};
|
||||
};
|
||||
|
||||
class rectangle : public shape {
|
||||
public:
|
||||
explicit rectangle(double width, double height)
|
||||
: width_{width}
|
||||
, height_{height} {}
|
||||
|
||||
double area() const override {
|
||||
return width_ * height_;
|
||||
}
|
||||
|
||||
double width() const {
|
||||
return width_;
|
||||
}
|
||||
|
||||
double height() const {
|
||||
return height_;
|
||||
}
|
||||
private:
|
||||
double width_{};
|
||||
double height_{};
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE("meta/examples/class") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
meta::class_<shape>()
|
||||
.method_("area", &shape::area);
|
||||
|
||||
meta::class_<circle>()
|
||||
.base_<shape>()
|
||||
.ctor_<double>()
|
||||
.method_("radius", &circle::radius);
|
||||
|
||||
meta::class_<rectangle>()
|
||||
.base_<shape>()
|
||||
.ctor_<double, double>()
|
||||
.method_("width", &rectangle::width)
|
||||
.method_("height", &rectangle::height);
|
||||
|
||||
const meta::scope geometry = meta::local_scope_("geometry")
|
||||
.class_<shape>("shape")
|
||||
.class_<circle>("circle")
|
||||
.class_<rectangle>("rectangle");
|
||||
|
||||
const meta::class_type shape_type = geometry.get_class("shape");
|
||||
const meta::method area_method = shape_type.get_method("area");
|
||||
|
||||
{
|
||||
const meta::class_type circle_type = geometry.get_class("circle");
|
||||
const meta::method radius_method = circle_type.get_method("radius");
|
||||
|
||||
const meta::value circle_v = circle_type.create(5.0).value();
|
||||
|
||||
const meta::value circle_area_v = area_method(circle_v).value();
|
||||
const meta::value circle_radius_v = radius_method(circle_v).value();
|
||||
|
||||
CHECK(circle_area_v.cast<double>() == doctest::Approx(78.5).epsilon(0.1));
|
||||
CHECK(circle_radius_v == 5.0);
|
||||
}
|
||||
|
||||
{
|
||||
const meta::class_type rectangle_type = geometry.get_class("rectangle");
|
||||
const meta::method width_method = rectangle_type.get_method("width");
|
||||
const meta::method height_method = rectangle_type.get_method("height");
|
||||
|
||||
const meta::value rectangle_v = rectangle_type.create(10.0, 20.0).value();
|
||||
|
||||
const meta::value rectangle_area_v = area_method(rectangle_v).value();
|
||||
const meta::value rectangle_width_v = width_method(rectangle_v).value();
|
||||
const meta::value rectangle_height_v = height_method(rectangle_v).value();
|
||||
|
||||
CHECK(rectangle_area_v.cast<double>() == doctest::Approx(200.0).epsilon(0.1));
|
||||
CHECK(rectangle_width_v == 10.0);
|
||||
CHECK(rectangle_height_v == 20.0);
|
||||
}
|
||||
}
|
||||
@@ -1,99 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
struct ivec2 {
|
||||
int x{};
|
||||
int y{};
|
||||
|
||||
ivec2() = default;
|
||||
ivec2(int v) : x{v}, y{v} {}
|
||||
ivec2(int x, int y) : x{x}, y{y} {}
|
||||
|
||||
int dot(const ivec2& other) const {
|
||||
return x * other.x + y * other.y;
|
||||
}
|
||||
|
||||
int length2() const {
|
||||
return dot(*this);
|
||||
}
|
||||
|
||||
friend bool operator==(const ivec2& l, const ivec2& r) {
|
||||
return l.x == r.x && l.y == r.y;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE("meta/examples/complex") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
meta::class_<ivec2>()
|
||||
.ctor_<>()
|
||||
.ctor_<int>()
|
||||
.ctor_<int, int>()
|
||||
.member_("x", &ivec2::x)
|
||||
.member_("y", &ivec2::y)
|
||||
.method_("dot", &ivec2::dot)
|
||||
.method_("length2", &ivec2::length2);
|
||||
|
||||
const meta::class_type ivec2_type = meta::resolve_type<ivec2>();
|
||||
|
||||
const meta::member ivec2_x = ivec2_type.get_member("x");
|
||||
const meta::member ivec2_y = ivec2_type.get_member("y");
|
||||
|
||||
const meta::method ivec2_dot = ivec2_type.get_method("dot");
|
||||
const meta::method ivec2_length2 = ivec2_type.get_method("length2");
|
||||
|
||||
{
|
||||
const ivec2 v = ivec2_type()->cast<ivec2>();
|
||||
CHECK(v == ivec2{});
|
||||
|
||||
CHECK(ivec2_x(v) == 0);
|
||||
CHECK(ivec2_y(v) == 0);
|
||||
}
|
||||
|
||||
{
|
||||
const ivec2 v = ivec2_type(3)->cast<ivec2>();
|
||||
CHECK(v == ivec2{3});
|
||||
|
||||
CHECK(ivec2_x(v) == 3);
|
||||
CHECK(ivec2_y(v) == 3);
|
||||
}
|
||||
|
||||
{
|
||||
const meta::value v = ivec2_type(1, 2).value();
|
||||
CHECK(v == ivec2{1, 2});
|
||||
|
||||
CHECK(ivec2_x(v) == 1);
|
||||
CHECK(ivec2_y(v) == 2);
|
||||
}
|
||||
|
||||
{
|
||||
meta::value v = ivec2_type(1, 2).value();
|
||||
|
||||
ivec2_x(v, 10);
|
||||
ivec2_y(v, 20);
|
||||
|
||||
CHECK(ivec2_x(v) == 10);
|
||||
CHECK(ivec2_y(v) == 20);
|
||||
}
|
||||
|
||||
{
|
||||
const meta::value v0 = ivec2_type(1, 2).value();
|
||||
const meta::value v1 = ivec2_type(3, 4).value();
|
||||
|
||||
CHECK(ivec2_dot(v0, v1) == 1 * 3 + 2 * 4);
|
||||
}
|
||||
|
||||
{
|
||||
const meta::value v = ivec2_type(3, 4).value();
|
||||
|
||||
CHECK(ivec2_length2(v) == 3 * 3 + 4 * 4);
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
enum class color : unsigned {
|
||||
red = 0xFF0000,
|
||||
green = 0x00FF00,
|
||||
blue = 0x0000FF,
|
||||
white = red | green | blue,
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE("meta/examples/enum") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
meta::enum_<color>()
|
||||
.evalue_("red", color::red)
|
||||
.evalue_("green", color::green)
|
||||
.evalue_("blue", color::blue)
|
||||
.evalue_("white", color::white);
|
||||
|
||||
meta::enum_type color_type = meta::resolve_type<color>();
|
||||
|
||||
{
|
||||
meta::number_type color_underlying_type = color_type.get_underlying_type();
|
||||
|
||||
CHECK(color_underlying_type.get_size() == 4);
|
||||
CHECK(color_underlying_type.get_flags().has(meta::number_flags::is_unsigned));
|
||||
}
|
||||
|
||||
{
|
||||
meta::evalue green_evalue = color_type.get_evalue("green");
|
||||
|
||||
CHECK(green_evalue.get_name() == "green");
|
||||
CHECK(green_evalue.get_type() == color_type);
|
||||
|
||||
CHECK(green_evalue.get_value() == color::green);
|
||||
}
|
||||
|
||||
{
|
||||
CHECK(color_type.value_to_name(color::blue) == "blue");
|
||||
CHECK(color_type.name_to_value("white") == color::white);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
struct ivec2 {
|
||||
int x{};
|
||||
int y{};
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE("meta/examples/member") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
meta::class_<ivec2>()
|
||||
.member_("x", &ivec2::x)
|
||||
.member_("y", &ivec2::y);
|
||||
|
||||
const meta::class_type ivec2_type = meta::resolve_type<ivec2>();
|
||||
|
||||
CHECK(ivec2_type.get_members().size() == 2);
|
||||
|
||||
{
|
||||
const meta::member ivec2_x = ivec2_type.get_member("x");
|
||||
|
||||
CHECK(ivec2_x.get_name() == "x");
|
||||
CHECK(ivec2_x.get_type() == meta::resolve_type<decltype(&ivec2::x)>());
|
||||
|
||||
CHECK(ivec2_x.get_type().get_owner_type() == meta::resolve_type<ivec2>());
|
||||
CHECK(ivec2_x.get_type().get_value_type() == meta::resolve_type<int>());
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
struct ivec2 {
|
||||
int x{};
|
||||
int y{};
|
||||
|
||||
int dot(const ivec2& other) const {
|
||||
return x * other.x + y * other.y;
|
||||
}
|
||||
|
||||
int length2() const {
|
||||
return dot(*this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE("meta/examples/method") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
meta::class_<ivec2>()
|
||||
.member_("x", &ivec2::x)
|
||||
.member_("y", &ivec2::y)
|
||||
.method_("dot", &ivec2::dot)
|
||||
.method_("length2", &ivec2::length2);
|
||||
|
||||
const meta::class_type ivec2_type = meta::resolve_type<ivec2>();
|
||||
|
||||
CHECK(ivec2_type.get_methods().size() == 2);
|
||||
|
||||
{
|
||||
const meta::method ivec2_dot = ivec2_type.get_method("dot");
|
||||
|
||||
CHECK(ivec2_dot.get_name() == "dot");
|
||||
CHECK(ivec2_dot.get_type() == meta::resolve_type<decltype(&ivec2::dot)>());
|
||||
|
||||
CHECK(ivec2_dot.get_type().get_arity() == 1);
|
||||
CHECK(ivec2_dot.get_type().get_return_type() == meta::resolve_type<int>());
|
||||
CHECK(ivec2_dot.get_type().get_argument_type(0) == meta::resolve_type<const ivec2&>());
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
}
|
||||
|
||||
TEST_CASE("meta/examples/number") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
{
|
||||
const meta::number_type int_type = meta::resolve_type<int>();
|
||||
|
||||
CHECK(int_type.get_flags().has(meta::number_flags::is_signed));
|
||||
CHECK(int_type.get_size() == sizeof(int));
|
||||
}
|
||||
|
||||
{
|
||||
const meta::number_type unsigned_type = meta::resolve_type<unsigned>();
|
||||
|
||||
CHECK(unsigned_type.get_flags().has(meta::number_flags::is_unsigned));
|
||||
CHECK(unsigned_type.get_size() == sizeof(unsigned));
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -26,7 +26,7 @@ namespace
|
||||
struct E {};
|
||||
}
|
||||
|
||||
TEST_CASE("features/features/diamond_inheritance") {
|
||||
TEST_CASE("meta/meta_features/diamond") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
meta::class_<A>();
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
11
untests/meta_untests.hpp
Normal file
11
untests/meta_untests.hpp
Normal file
@@ -0,0 +1,11 @@
|
||||
/*******************************************************************************
|
||||
* This file is part of the "https://github.com/blackmatov/meta.hpp"
|
||||
* For conditions of distribution and use, see copyright notice in LICENSE.md
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include <meta.hpp/meta_all.hpp>
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -44,7 +44,7 @@ namespace
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE("features/meta_utilities/arg2") {
|
||||
TEST_CASE("meta/meta_utilities/arg2") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
// * <- B <- *
|
||||
@@ -57,7 +57,7 @@ TEST_CASE("features/meta_utilities/arg2") {
|
||||
meta::class_<D>().base_<B>().base_<C>();
|
||||
}
|
||||
|
||||
TEST_CASE("features/meta_utilities/arg2/cast") {
|
||||
TEST_CASE("meta/meta_utilities/arg2/cast") {
|
||||
namespace meta = meta_hpp;
|
||||
using meta::detail::arg;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -37,7 +37,7 @@ namespace
|
||||
};
|
||||
}
|
||||
|
||||
TEST_CASE("features/meta_utilities/arg3") {
|
||||
TEST_CASE("meta/meta_utilities/arg3") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
// * <- B <- *
|
||||
@@ -50,7 +50,7 @@ TEST_CASE("features/meta_utilities/arg3") {
|
||||
meta::class_<D>().base_<B>().base_<C>();
|
||||
}
|
||||
|
||||
TEST_CASE("features/meta_utilities/arg3/cast") {
|
||||
TEST_CASE("meta/meta_utilities/arg3/cast") {
|
||||
namespace meta = meta_hpp;
|
||||
using meta::detail::arg;
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
TEST_CASE("features/meta_utilities/arg4/cast") {
|
||||
TEST_CASE("meta/meta_utilities/arg4/cast") {
|
||||
namespace meta = meta_hpp;
|
||||
using meta::detail::arg;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -107,7 +107,7 @@ namespace
|
||||
}\
|
||||
}
|
||||
|
||||
TEST_CASE("features/meta_utilities/arg") {
|
||||
TEST_CASE("meta/meta_utilities/arg") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
meta::class_<fake>();
|
||||
@@ -115,7 +115,7 @@ TEST_CASE("features/meta_utilities/arg") {
|
||||
meta::class_<dclazz>().base_<fake>().base_<clazz>();
|
||||
}
|
||||
|
||||
TEST_CASE("features/meta_utilities/arg/refs") {
|
||||
TEST_CASE("meta/meta_utilities/arg/refs") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
{
|
||||
@@ -303,7 +303,7 @@ TEST_CASE("features/meta_utilities/arg/refs") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("features/meta_utilities/arg/ptrs") {
|
||||
TEST_CASE("meta/meta_utilities/arg/ptrs") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
{
|
||||
@@ -837,7 +837,7 @@ TEST_CASE("features/meta_utilities/arg/ptrs") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("features/meta_utilities/arg/values") {
|
||||
TEST_CASE("meta/meta_utilities/arg/values") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
{
|
||||
@@ -1027,7 +1027,7 @@ TEST_CASE("features/meta_utilities/arg/values") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("features/meta_utilities/arg/ptr_values") {
|
||||
TEST_CASE("meta/meta_utilities/arg/ptr_values") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
{
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
TEST_CASE("features/meta_utilities/detail") {
|
||||
TEST_CASE("meta/meta_utilities/detail") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
SUBCASE("cvref_traits") {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -67,7 +67,7 @@ namespace
|
||||
}\
|
||||
}
|
||||
|
||||
TEST_CASE("features/meta_utilities/inst2") {
|
||||
TEST_CASE("meta/meta_utilities/inst2") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
meta::class_<fake>();
|
||||
@@ -75,7 +75,7 @@ TEST_CASE("features/meta_utilities/inst2") {
|
||||
meta::class_<dclazz>().base_<fake>().base_<clazz>();
|
||||
}
|
||||
|
||||
TEST_CASE("features/meta_utilities/inst2/refs") {
|
||||
TEST_CASE("meta/meta_utilities/inst2/refs") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
{
|
||||
@@ -235,7 +235,7 @@ TEST_CASE("features/meta_utilities/inst2/refs") {
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("features/meta_utilities/inst2/values") {
|
||||
TEST_CASE("meta/meta_utilities/inst2/values") {
|
||||
namespace meta = meta_hpp;
|
||||
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2021, by Matvey Cherevko (blackmatov@gmail.com)
|
||||
******************************************************************************/
|
||||
|
||||
#include "../meta_tests.hpp"
|
||||
#include "../meta_untests.hpp"
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -90,10 +90,10 @@ TEST_CASE("meta/meta_utilities/value") {
|
||||
|
||||
CHECK(val.get_type() == meta::resolve_type<ivec2>());
|
||||
|
||||
CHECK(!std::memcmp(val.data(), &vr, sizeof(ivec2)));
|
||||
CHECK(!std::memcmp(val.cdata(), &vr, sizeof(ivec2)));
|
||||
CHECK(!std::memcmp(std::as_const(val).data(), &vr, sizeof(ivec2)));
|
||||
CHECK(!std::memcmp(std::as_const(val).cdata(), &vr, sizeof(ivec2)));
|
||||
CHECK(*static_cast<const ivec2*>(val.data()) == vr);
|
||||
CHECK(*static_cast<const ivec2*>(val.cdata()) == vr);
|
||||
CHECK(*static_cast<const ivec2*>(std::as_const(val).data()) == vr);
|
||||
CHECK(*static_cast<const ivec2*>(std::as_const(val).cdata()) == vr);
|
||||
|
||||
CHECK(val == ivec2{1,2});
|
||||
CHECK(val == meta::value{ivec2{1,2}});
|
||||
@@ -115,10 +115,10 @@ TEST_CASE("meta/meta_utilities/value") {
|
||||
|
||||
CHECK(val.get_type() == meta::resolve_type<ivec2>());
|
||||
|
||||
CHECK(!std::memcmp(val.data(), &vr, sizeof(ivec2)));
|
||||
CHECK(!std::memcmp(val.cdata(), &vr, sizeof(ivec2)));
|
||||
CHECK(!std::memcmp(std::as_const(val).data(), &vr, sizeof(ivec2)));
|
||||
CHECK(!std::memcmp(std::as_const(val).cdata(), &vr, sizeof(ivec2)));
|
||||
CHECK(*static_cast<const ivec2*>(val.data()) == vr);
|
||||
CHECK(*static_cast<const ivec2*>(val.cdata()) == vr);
|
||||
CHECK(*static_cast<const ivec2*>(std::as_const(val).data()) == vr);
|
||||
CHECK(*static_cast<const ivec2*>(std::as_const(val).cdata()) == vr);
|
||||
|
||||
CHECK(val == ivec2{1,2});
|
||||
CHECK(val == meta::value{ivec2{1,2}});
|
||||
|
||||
Reference in New Issue
Block a user