Skip to content

Commit 3a5b0ac

Browse files
committed
Added excerpt from mplex library for boost::optional detection.
1 parent b764902 commit 3a5b0ac

File tree

5 files changed

+137
-0
lines changed

5 files changed

+137
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef MPLEX_FUNDAMENTAL_EVAL_IF_HPP_INCLUDED
2+
#define MPLEX_FUNDAMENTAL_EVAL_IF_HPP_INCLUDED
3+
4+
#include "integral.hpp"
5+
6+
namespace mplex {
7+
8+
template <typename Condition, typename Fallback, typename Function, typename... Parameters>
9+
struct eval_if_default
10+
{
11+
using type = Fallback; // TODO: think about something more meaningfull here
12+
};
13+
14+
template <typename Fallback, typename Function, typename... Parameters>
15+
struct eval_if_default <true_, Fallback, Function, Parameters...>
16+
{
17+
using type = typename Function::template apply <Parameters...>::type;
18+
};
19+
20+
template <typename Condition, typename Function, typename... Parameters>
21+
struct eval_if
22+
{
23+
using type = void; // TODO: think about something more meaningfull here
24+
};
25+
26+
template <typename Function, typename... Parameters>
27+
struct eval_if <true_, Function, Parameters...>
28+
{
29+
using type = typename Function::template apply <Parameters...>::type;
30+
};
31+
32+
template <typename Condition, typename Function, typename... Parameters>
33+
using eval_if_t = typename eval_if <Condition, Function, Parameters...>::type;
34+
35+
template <typename Condition, typename Fallback, typename Function, typename... Parameters>
36+
using eval_if_default_t = typename eval_if_default <Condition, Fallback, Function, Parameters...>::type;
37+
}
38+
39+
#endif // MPLEX_FUNDAMENTAL_EVAL_IF_HPP_INCLUDED
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef IDENTITY_HPP_INCLUDED
2+
#define IDENTITY_HPP_INCLUDED
3+
4+
namespace mplex {
5+
template <typename T>
6+
struct identity {
7+
using type = T;
8+
};
9+
10+
struct identity_functor {
11+
template <typename T>
12+
struct apply {
13+
using type = T;
14+
};
15+
};
16+
}
17+
18+
#endif // IDENTITY_HPP_INCLUDED
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#ifndef MPLEX_FUNDAMENTAL_INTEGRAL_HPP_INCLUDED
2+
#define MPLEX_FUNDAMENTAL_INTEGRAL_HPP_INCLUDED
3+
4+
#include <type_traits>
5+
#include <cstdint>
6+
7+
namespace mplex
8+
{
9+
template <typename T, T Value>
10+
using integral = std::integral_constant <T, Value>;
11+
12+
#define DECLARE_INTEGRAL(TYPE) \
13+
template <TYPE V> \
14+
using TYPE ## _ = mplex::integral <TYPE, V>
15+
16+
#define DECLARE_INTEGRAL_N(TYPE, NAME) \
17+
template <TYPE V> \
18+
using NAME ## _ = mplex::integral <TYPE, V>
19+
20+
DECLARE_INTEGRAL(bool);
21+
DECLARE_INTEGRAL(int);
22+
DECLARE_INTEGRAL(long);
23+
DECLARE_INTEGRAL_N(long long, long_long);
24+
DECLARE_INTEGRAL(short);
25+
DECLARE_INTEGRAL(unsigned);
26+
27+
DECLARE_INTEGRAL_N(unsigned int, unsigned_int);
28+
DECLARE_INTEGRAL_N(unsigned long, unsigned_long);
29+
DECLARE_INTEGRAL_N(unsigned long long, unsigned_long_long);
30+
DECLARE_INTEGRAL_N(unsigned short, unsigned_short);
31+
32+
DECLARE_INTEGRAL(uint8_t);
33+
DECLARE_INTEGRAL(uint16_t);
34+
DECLARE_INTEGRAL(uint32_t);
35+
DECLARE_INTEGRAL(uint64_t);
36+
37+
DECLARE_INTEGRAL(int8_t);
38+
DECLARE_INTEGRAL(int16_t);
39+
DECLARE_INTEGRAL(int32_t);
40+
DECLARE_INTEGRAL(int64_t);
41+
42+
using true_ = bool_ <true>;
43+
using false_ = bool_ <false>;
44+
}
45+
46+
#endif // MPLEX_FUNDAMENTAL_INTEGRAL_HPP_INCLUDED
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#ifndef IS_SAME_HPP_INCLUDED
2+
#define IS_SAME_HPP_INCLUDED
3+
4+
#include <type_traits>
5+
#include "integral.hpp"
6+
7+
namespace mplex {
8+
struct is_same {
9+
template <typename T, typename U>
10+
struct apply {
11+
using type = bool_ <std::is_same<T, U>::value>;
12+
constexpr static const bool value = type::value;
13+
};
14+
};
15+
16+
template <typename T>
17+
struct is_type {
18+
template <typename U>
19+
struct apply {
20+
using type = bool_ <std::is_same<T, U>::value>;
21+
constexpr static const bool value = type::value;
22+
};
23+
};
24+
}
25+
26+
#endif // IS_SAME_HPP_INCLUDED
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef MPLEX_FUNDAMENTAL_NULL_TYPE_HPP_INCLUDED
2+
#define MPLEX_FUNDAMENTAL_NULL_TYPE_HPP_INCLUDED
3+
4+
namespace mplex {
5+
struct null_t {};
6+
}
7+
8+
#endif // MPLEX_FUNDAMENTAL_NULL_TYPE_HPP_INCLUDED

0 commit comments

Comments
 (0)