forked from boostorg/describe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
9 changed files
with
274 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// Copyright (c) 2022 Klemens Morgenstern ([email protected]) | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
|
||
#ifndef BOOST_DESCRIBE_CONSTRUCTOR_HPP_INCLUDED | ||
#define BOOST_DESCRIBE_CONSTRUCTOR_HPP_INCLUDED | ||
|
||
#include <boost/describe/modifiers.hpp> | ||
#include <boost/describe/detail/void_t.hpp> | ||
#include <boost/describe/detail/config.hpp> | ||
|
||
|
||
#if defined(BOOST_DESCRIBE_CXX11) | ||
|
||
#include <boost/mp11/algorithm.hpp> | ||
#include <type_traits> | ||
|
||
namespace boost | ||
{ | ||
namespace describe | ||
{ | ||
namespace detail | ||
{ | ||
|
||
template<class T> using _describe_ctors = decltype( boost_ctor_descriptor_fn( static_cast<T**>(0) ) ); | ||
|
||
template<class T, class En = void> struct has_describe_ctors: std::false_type | ||
{ | ||
}; | ||
|
||
template<class T> struct has_describe_ctors<T, void_t<_describe_ctors<T>>>: std::true_type | ||
{ | ||
}; | ||
|
||
} | ||
|
||
template<class T> using describe_constructors = detail::_describe_ctors<T>; | ||
|
||
template<class T> using has_describe_constructors = detail::has_describe_ctors<T>; | ||
|
||
} | ||
} | ||
|
||
#endif // !defined(BOOST_DESCRIBE_CXX11) | ||
|
||
#endif //BOOST_DESCRIBE_CONSTRUCTOR_HPP_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// Copyright (c) 2022 Klemens Morgenstern ([email protected]) | ||
// | ||
// Distributed under the Boost Software License, Version 1.0. (See accompanying | ||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | ||
// | ||
|
||
#ifndef BOOST_DESCRIBE_DETAIL_CONSTRUCTOR_HPP_INCLUDED | ||
#define BOOST_DESCRIBE_DETAIL_CONSTRUCTOR_HPP_INCLUDED | ||
|
||
#include <boost/describe/modifiers.hpp> | ||
#include <type_traits> | ||
|
||
namespace boost | ||
{ | ||
namespace describe | ||
{ | ||
namespace detail | ||
{ | ||
|
||
template<class S> | ||
struct ctor_descriptor; | ||
|
||
template<class C, class ... Args> | ||
struct ctor_descriptor<C(Args...)> | ||
{ | ||
using signature = C(Args...); | ||
static constexpr unsigned modifiers = mod_constructor; | ||
static constexpr bool is_noexcept = std::is_nothrow_constructible<C, Args...>::value; | ||
static constexpr bool is_trivial = std::is_trivially_constructible<C, Args...>::value; | ||
|
||
constexpr static C* construct_at(C* p, Args... args) | ||
{ | ||
return new (p) C(static_cast<Args>(args)...); | ||
} | ||
}; | ||
|
||
template<class... T> auto ctor_descriptor_fn_impl( int, T... ) | ||
{ | ||
return list<T...>(); | ||
} | ||
|
||
#define BOOST_DESCRIBE_CTOR_IMPL(C, B) , boost::describe::detail::ctor_descriptor<C B>() | ||
|
||
|
||
#if defined(_MSC_VER) && !defined(__clang__) | ||
|
||
#define BOOST_DESCRIBE_CTORS(C, ...) inline auto boost_ctor_descriptor_fn( C** ) \ | ||
{ return boost::describe::detail::ctor_descriptor_fn_impl( 0 BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_CTOR_IMPL, C, __VA_ARGS__) ); } | ||
|
||
#else | ||
|
||
#define BOOST_DESCRIBE_CTORS(C, ...) inline auto boost_ctor_descriptor_fn( C** ) \ | ||
{ return boost::describe::detail::ctor_descriptor_fn_impl( 0 BOOST_DESCRIBE_PP_FOR_EACH(BOOST_DESCRIBE_CTOR_IMPL, C, ##__VA_ARGS__) ); } | ||
|
||
#endif | ||
|
||
} | ||
} | ||
} | ||
|
||
#endif //BOOST_DESCRIBE_DETAIL_CONSTRUCTOR_HPP_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright 2020 Peter Dimov | ||
// Distributed under the Boost Software License, Version 1.0. | ||
// https://www.boost.org/LICENSE_1_0.txt | ||
|
||
#include <boost/describe/members.hpp> | ||
#include <boost/describe/constructor.hpp> | ||
#include <boost/describe/class.hpp> | ||
#include <boost/core/lightweight_test.hpp> | ||
#include <utility> | ||
|
||
class X | ||
{ | ||
private: | ||
|
||
std::pair<int, int> p_; | ||
|
||
|
||
X() : p_(0,0) {} | ||
public: | ||
X(int x, int y) noexcept : p_(x, y) {} | ||
X(const std::pair<int, int> & p) : p_(p) {} | ||
BOOST_DESCRIBE_CLASS(X, (), (), (), (p_)); | ||
BOOST_DESCRIBE_CLASS_CONSTRUCTORS(X, (), (int, int), (const std::pair<int, int>&)); | ||
|
||
int x() {return p_.first; } | ||
int y() {return p_.second; } | ||
}; | ||
|
||
|
||
#if !defined(BOOST_DESCRIBE_CXX14) | ||
|
||
#include <boost/config/pragma_message.hpp> | ||
|
||
BOOST_PRAGMA_MESSAGE("Skipping test because C++14 is not available") | ||
int main() {} | ||
|
||
#else | ||
|
||
#include <boost/mp11.hpp> | ||
|
||
|
||
int main() | ||
{ | ||
using namespace boost::describe; | ||
using namespace boost::mp11; | ||
|
||
{ | ||
|
||
X x(1, 2); | ||
BOOST_TEST_EQ(x.x(), 1); | ||
BOOST_TEST_EQ(x.y(), 2); | ||
using L1 = describe_constructors<X>; | ||
|
||
BOOST_TEST_EQ( mp_size<L1>::value, 3 ); | ||
|
||
using C1 = mp_at_c<L1, 0>; | ||
BOOST_TEST( (std::is_same<C1::signature, X() >::value) ); | ||
BOOST_TEST_EQ( C1::modifiers, mod_constructor ); | ||
BOOST_TEST_EQ( C1::is_noexcept, false ); | ||
BOOST_TEST_EQ( C1::is_trivial, false ); | ||
BOOST_TEST_EQ(&x, C1::construct_at(&x)); | ||
BOOST_TEST_EQ(x.x(), 0); | ||
BOOST_TEST_EQ(x.y(), 0); | ||
|
||
using C2 = mp_at_c<L1, 1>; | ||
BOOST_TEST( (std::is_same<C2::signature, X(int, int) >::value) ); | ||
BOOST_TEST_EQ( C2::modifiers, mod_constructor ); | ||
BOOST_TEST_EQ( C2::is_noexcept, true ); | ||
BOOST_TEST_EQ( C2::is_trivial, false ); | ||
BOOST_TEST_EQ(&x, C2::construct_at(&x, 3, 4)); | ||
BOOST_TEST_EQ(x.x(), 3); | ||
BOOST_TEST_EQ(x.y(), 4); | ||
|
||
using C3 = mp_at_c<L1, 2>; | ||
BOOST_TEST( (std::is_same<C3::signature, X(const std::pair<int, int> &) >::value) ); | ||
BOOST_TEST_EQ( C3::modifiers, mod_constructor ); | ||
BOOST_TEST_EQ( C3::is_noexcept, false ); | ||
BOOST_TEST_EQ( C3::is_trivial, false ); | ||
BOOST_TEST_EQ(&x, C3::construct_at(&x, {5,6})); | ||
BOOST_TEST_EQ(x.x(), 5); | ||
BOOST_TEST_EQ(x.y(), 6); | ||
|
||
} | ||
|
||
return boost::report_errors(); | ||
} | ||
|
||
#endif // !defined(BOOST_DESCRIBE_CXX14) |