Skip to content

Commit ae122a2

Browse files
committed
introduce <macro>, new feature macro approach, use dollar macros more consistently
1 parent 291b26b commit ae122a2

File tree

15 files changed

+89
-68
lines changed

15 files changed

+89
-68
lines changed

include/rsl/_impl/_config.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
#include <rsl/macro>
3+
// this file contains defaults for feature macros used in rsl-util
4+
5+
#define OPT_RSL_STD_COMPAT OPT_DEFAULT_ON // RSL_STD_COMPAT
6+
#define OPT_RSL_POISON_STD OPT_DEFAULT_OFF // RSL_POISON_STD
7+
#define OPT_RSL_ENABLE_REVIEW OPT_DEFAULT_OFF // RSL_ENABLE_REVIEW
8+
#define OPT_RSL_GLOBAL_REPR OPT_DEFAULT_ON // RSL_GLOBAL_REPR

include/rsl/_impl/macro/attributes.hpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,4 @@
2424
# define RSL_ENABLE_IF(...) __attribute__((enable_if(__VA_ARGS__)))
2525
#else
2626
# define RSL_ENABLE_IF(...)
27-
#endif
28-
29-
#define $inline(...) RSL_INLINE(__VA_ARGS__)
30-
#define $enable_if(...) RSL_ENABLE_IF(__VA_ARGS__)
27+
#endif

include/rsl/_impl/macro/compiler.hpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@
88

99
#define RSL_VERSION_ENCODE(major, minor, patch) ((major) * 1000000 + (minor) * 1000 + (patch))
1010

11-
#ifndef __has_attribute
12-
# define __has_attribute(x) 0
13-
#endif
14-
15-
#ifndef __has_cpp_attribute
16-
# define __has_cpp_attribute(x) 0
17-
#endif
18-
1911
#if defined(__clang__)
2012
# define RSL_COMPILER RSL_COMPILER_CLANG
2113
# define RSL_COMPILER_VERSION \

include/rsl/_impl/macro/opt.hpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#define OPT_ +
4+
#define OPT_true +
5+
#define OPT_1 +
6+
#define OPT_on +
7+
#define OPT_ON +
8+
#define OPT_false -
9+
#define OPT_0 -
10+
#define OPT_off -
11+
#define OPT_OFF -
12+
13+
#define OPT_DEFAULT_ON +
14+
#define OPT_DEFAULT_OFF -
15+
16+
#define OPT_IMPL_EXPAND(x) OPT_##x
17+
#define USES_OPT(x) ((OPT_IMPL_EXPAND(x) 1) == 1)

include/rsl/_impl/macros.hpp

Lines changed: 0 additions & 7 deletions
This file was deleted.

include/rsl/_impl/member_cache.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <meta>
66
#include <algorithm>
77

8-
#include <rsl/_impl/macro/attributes.hpp>
8+
#include <rsl/macro>
99

1010
namespace rsl::_impl {
1111
template <std::meta::info... Members>

include/rsl/_impl/platform/io.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#pragma once
2+
#include <rsl/macro>
23

3-
#ifdef __unix__
4+
#if $os_is(LINUX)
45
# include <unistd.h>
5-
#elif defined(_WIN32) || defined(WIN32)
6+
#elif $os_is(WINDOWS)
67
# define WIN32_LEAN_AND_MEAN
78
# include <windows.h>
89

@@ -21,10 +22,12 @@
2122

2223
namespace rsl::_impl_platform {
2324
inline bool isatty(int fd) {
24-
#if __unix__
25+
#if $os_is(LINUX)
2526
return bool(::isatty(fd));
26-
#else
27+
#elif $os_is(WINDOWS)
2728
return bool(::_isatty(fd));
29+
#else
30+
# error "Unsupported platform"
2831
#endif
2932
}
3033

include/rsl/assert

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,9 @@
1111
#include <rsl/source_location>
1212
#include <rsl/expect>
1313
#include <rsl/string_view>
14-
#include <rsl/_impl/util/to_string.hpp>
15-
#include "_impl/macros.hpp"
16-
17-
#define RSL_REVIEW_DEFAULT 1
1814

19-
#if !defined(RSL_ENABLE_REVIEW)
20-
# define RSL_IMPL_ENABLE_REVIEW 0
21-
#else
22-
# if RSL_IMPL_IS_EMPTY(RSL_ENABLE_REVIEW)
23-
# define RSL_IMPL_ENABLE_REVIEW 1
24-
# else
25-
# define RSL_IMPL_ENABLE_REVIEW RSL_ENABLE_REVIEW
26-
# endif
27-
#endif
15+
#include <rsl/_impl/util/to_string.hpp>
16+
#include <rsl/_impl/_config.h>
2817

2918
namespace rsl {
3019
namespace _error_impl {
@@ -89,7 +78,7 @@ constexpr void assert_violation(std::source_location sloc,
8978
}
9079
}
9180

92-
#if RSL_IMPL_ENABLE_REVIEW
81+
#if $uses_opt(RSL_ENABLE_REVIEW)
9382

9483
inline std::vector<std::string>& observations() {
9584
static std::vector<std::string> value;
@@ -156,7 +145,7 @@ constexpr bool assert_condition_wrapper(bool result, std::string_view message =
156145
}(); \
157146
} while (false)
158147

159-
#if RSL_IMPL_ENABLE_REVIEW
148+
#if $uses_opt(RSL_ENABLE_REVIEW)
160149
# define constexpr_review(...) \
161150
do { \
162151
static constexpr auto _sloc = ::rsl::source_location(); \

include/rsl/enum

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <type_traits>
55
#include <utility>
66
#include <rsl/meta_traits>
7+
#include <rsl/_impl/_config.h>
8+
79

810
namespace rsl {
911
inline namespace annotations {
@@ -198,12 +200,6 @@ constexpr bool in_range(U value) noexcept {
198200
}
199201
} // namespace rsl
200202

201-
#ifdef RSL_POISON_STD
202-
template <typename E>
203-
requires std::is_enum_v<E>
204-
struct std::numeric_limits<E> : rsl::numeric_limits<E> {};
205-
#endif
206-
207203
template <rsl::is_flag_enum E>
208204
requires std::is_scoped_enum_v<E>
209205
constexpr E operator~(E v) noexcept {

include/rsl/macro

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
#include <rsl/_impl/macro/attributes.hpp>
3+
#include <rsl/_impl/macro/compiler.hpp>
4+
#include <rsl/_impl/macro/opt.hpp>
5+
#include <rsl/_impl/macro/os.hpp>
6+
7+
// compile environment checks
8+
9+
/**
10+
* @param compiler: one of UNKNOWN, CLANG, GCC, MSVC
11+
*/
12+
#define $compiler_is(compiler) (RSL_COMPILER == RSL_COMPILER_##compiler)
13+
14+
/**
15+
* @param stdlib: one of UNKNOWN, LIBCXX, GLIBCXX, MSVC
16+
*/
17+
#define $stdlib_is(stdlib) (RSL_STDLIB == RSL_STDLIB_##stdlib)
18+
19+
/**
20+
* @param os: one of UNKNOWN, WINDOWS, LINUX, MAC, FREEBSD, ANDROID, IOS
21+
*/
22+
#define $os_is(os) (RSL_OS == RSL_OS_##os)
23+
24+
// feature macro helper
25+
#define $uses_opt(x) USES_OPT(x)
26+
27+
// attributes
28+
#define $inline(...) RSL_INLINE(__VA_ARGS__)
29+
#define $enable_if(...) RSL_ENABLE_IF(__VA_ARGS__)

0 commit comments

Comments
 (0)