compacted namespaces a bit
diff --git a/.clang-format b/.clang-format
index 0dee6af..5493c78 100644
--- a/.clang-format
+++ b/.clang-format
@@ -21,6 +21,7 @@
IndentCaseLabels: true
ContinuationIndentWidth: 8
NamespaceIndentation: Inner
+CompactNamespaces: true
FixNamespaceComments: true
AccessModifierOffset: -4
@@ -62,7 +63,7 @@
BraceWrapping:
AfterClass: true
AfterEnum: true
- AfterNamespace: true
+ AfterNamespace: false
AfterStruct: true
AfterUnion: true
diff --git a/doctest/doctest.h b/doctest/doctest.h
index b473750..e59d823 100644
--- a/doctest/doctest.h
+++ b/doctest/doctest.h
@@ -395,8 +395,7 @@
// so the <iosfwd> header is used - also it is very light and doesn't drag a ton of stuff
#include <iosfwd>
#else // _LIBCPP_VERSION
-namespace std
-{
+namespace std {
template <class charT>
struct char_traits;
template <>
@@ -410,8 +409,7 @@
#ifdef _LIBCPP_VERSION
#include <cstddef>
#else // _LIBCPP_VERSION
-namespace std
-{
+namespace std {
typedef decltype(nullptr) nullptr_t;
}
#endif // _LIBCPP_VERSION
@@ -420,10 +418,8 @@
#include <type_traits>
#endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
-namespace doctest
-{
-namespace detail
-{
+namespace doctest {
+namespace detail {
// the function type this library works with
typedef void (*funcType)();
} // namespace detail
@@ -514,8 +510,7 @@
DOCTEST_INTERFACE std::ostream& operator<<(std::ostream& s, const String& in);
-namespace Color
-{
+namespace Color {
enum Enum
{
None = 0,
@@ -538,8 +533,7 @@
DOCTEST_INTERFACE std::ostream& operator<<(std::ostream& s, Color::Enum code);
} // namespace Color
-namespace assertType
-{
+namespace assertType {
enum Enum
{
// macro traits
@@ -771,8 +765,7 @@
DOCTEST_DELETE_COPIES(ContextOptions);
};
-namespace detail
-{
+namespace detail {
#if defined(DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING) || defined(DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS)
template <bool CONDITION, typename TYPE = void>
struct enable_if
@@ -791,8 +784,7 @@
// to silence the warning "-Wzero-as-null-pointer-constant" only for gcc 5 for the Approx template ctor - pragmas don't work for it...
inline void* getNull() { return 0; }
- namespace has_insertion_operator_impl
- {
+ namespace has_insertion_operator_impl {
typedef char no;
typedef char yes[2];
@@ -1003,8 +995,7 @@
#if !defined(DOCTEST_CONFIG_DISABLE)
-namespace detail
-{
+namespace detail {
// clang-format off
#ifdef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
template<class T> struct decay_array { typedef T type; };
@@ -1310,8 +1301,7 @@
DOCTEST_INTERFACE int regTest(const TestCase& tc);
DOCTEST_INTERFACE int setTestSuite(const TestSuite& ts);
- namespace binaryAssertComparison
- {
+ namespace binaryAssertComparison {
enum Enum
{
eq = 0,
@@ -1372,8 +1362,7 @@
void react() const;
};
- namespace assertAction
- {
+ namespace assertAction {
enum Enum
{
nothing = 0,
@@ -1697,13 +1686,11 @@
// in a separate namespace outside of doctest because the DOCTEST_TEST_SUITE macro
// introduces an anonymous namespace in which getCurrentTestSuite gets overridden
-namespace doctest_detail_test_suite_ns
-{
+namespace doctest_detail_test_suite_ns {
DOCTEST_INTERFACE doctest::detail::TestSuite& getCurrentTestSuite();
} // namespace doctest_detail_test_suite_ns
-namespace doctest
-{
+namespace doctest {
#else // DOCTEST_CONFIG_DISABLE
template <typename T>
int registerExceptionTranslator(String (*)(T)) {
@@ -1713,8 +1700,7 @@
DOCTEST_INTERFACE bool isRunningInTest();
-namespace detail
-{
+namespace detail {
struct ContextState;
} // namespace detail
@@ -1744,8 +1730,7 @@
int run();
};
-namespace TestCaseFailureReason
-{
+namespace TestCaseFailureReason {
enum Enum
{
None = 0,
@@ -1860,8 +1845,7 @@
DOCTEST_GLOBAL_NO_WARNINGS_END()
#define DOCTEST_IMPLEMENT_FIXTURE(der, base, func, decorators) \
- namespace \
- { \
+ namespace { \
struct der : public base \
{ \
void f(); \
@@ -1895,10 +1879,7 @@
return "<" #__VA_ARGS__ ">"; \
}
#define DOCTEST_TYPE_TO_STRING(...) \
- namespace doctest \
- { \
- namespace detail \
- { \
+ namespace doctest { namespace detail { \
DOCTEST_TYPE_TO_STRING_IMPL(__VA_ARGS__) \
} \
} \
@@ -1976,10 +1957,7 @@
// for grouping tests in test suites by using code blocks
#define DOCTEST_TEST_SUITE_IMPL(decorators, ns_name) \
- namespace ns_name \
- { \
- namespace doctest_detail_test_suite_ns \
- { \
+ namespace ns_name { namespace doctest_detail_test_suite_ns { \
static DOCTEST_NOINLINE doctest::detail::TestSuite& getCurrentTestSuite() { \
static doctest::detail::TestSuite data; \
static bool inited = false; \
@@ -2340,8 +2318,7 @@
#else // DOCTEST_CONFIG_DISABLE
#define DOCTEST_IMPLEMENT_FIXTURE(der, base, func, name) \
- namespace \
- { \
+ namespace { \
template <typename DOCTEST_UNUSED_TEMPLATE_TYPE> \
struct der : public base \
{ void f(); }; \
@@ -2630,10 +2607,7 @@
DOCTEST_TEST_SUITE_END();
// add stringification for primitive/fundamental types
-namespace doctest
-{
-namespace detail
-{
+namespace doctest { namespace detail {
DOCTEST_TYPE_TO_STRING_IMPL(bool)
DOCTEST_TYPE_TO_STRING_IMPL(float)
DOCTEST_TYPE_TO_STRING_IMPL(double)
@@ -2650,8 +2624,7 @@
DOCTEST_TYPE_TO_STRING_IMPL(unsigned long int)
DOCTEST_TYPE_TO_STRING_IMPL(long long int)
DOCTEST_TYPE_TO_STRING_IMPL(unsigned long long int)
-} // namespace detail
-} // namespace doctest
+}} // namespace doctest::detail
#endif // DOCTEST_CONFIG_DISABLE
@@ -2792,12 +2765,10 @@
#define DOCTEST_BRANCH_ON_DISABLED(if_disabled, if_not_disabled) if_not_disabled
#endif // DOCTEST_CONFIG_DISABLE
-namespace doctest
-{
+namespace doctest {
void my_memcpy(void* dest, const void* src, unsigned num) { memcpy(dest, src, num); }
-namespace
-{
+namespace {
using namespace detail;
// case insensitive strcmp
int stricmp(const char* a, const char* b) {
@@ -2843,8 +2814,7 @@
};
} // namespace
-namespace detail
-{
+namespace detail {
void my_memcpy(void* dest, const void* src, unsigned num) { memcpy(dest, src, num); }
String rawMemoryToString(const void* object, unsigned size) {
@@ -3071,13 +3041,11 @@
std::ostream& operator<<(std::ostream& s, const String& in) { return s << in.c_str(); }
-namespace
-{
+namespace {
void color_to_stream(std::ostream&, Color::Enum) DOCTEST_BRANCH_ON_DISABLED({}, ;)
} // namespace
-namespace Color
-{
+namespace Color {
std::ostream& operator<<(std::ostream& s, Color::Enum code) {
color_to_stream(s, code);
return s;
@@ -3316,8 +3284,7 @@
} // namespace doctest
#ifdef DOCTEST_CONFIG_DISABLE
-namespace doctest
-{
+namespace doctest {
bool isRunningInTest() { return false; }
Context::Context(int, const char* const*) {}
Context::~Context() = default;
@@ -3401,8 +3368,7 @@
#endif // DOCTEST_PLATFORM_WINDOWS
-namespace doctest_detail_test_suite_ns
-{
+namespace doctest_detail_test_suite_ns {
// holds the current test suite
doctest::detail::TestSuite& getCurrentTestSuite() {
static doctest::detail::TestSuite data;
@@ -3410,10 +3376,8 @@
}
} // namespace doctest_detail_test_suite_ns
-namespace doctest
-{
-namespace
-{
+namespace doctest {
+namespace {
using namespace detail;
typedef std::map<std::pair<int, String>, IReporter*> reporterMap;
reporterMap& getReporters() {
@@ -3427,8 +3391,7 @@
#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
}
} // namespace
-namespace detail
-{
+namespace detail {
#define DOCTEST_ITERATE_THROUGH_REPORTERS(function, args) \
for(auto& curr_rep : g_contextState->reporters_currently_used) \
curr_rep->function(args)
@@ -3453,8 +3416,7 @@
}
} // namespace detail
-namespace
-{
+namespace {
using namespace detail;
// matching of a string against a wildcard mask (case sensitivity configurable) taken from
// https://www.codeproject.com/Articles/1088/Wildcard-string-compare-globbing
@@ -3559,8 +3521,7 @@
Timer g_timer;
} // namespace
-namespace detail
-{
+namespace detail {
const ContextOptions* getContextOptions() { return g_contextState; }
Subcase::Subcase(const char* name, const char* file, int line)
@@ -3697,8 +3658,7 @@
return m_template_id < other.m_template_id;
}
} // namespace detail
-namespace
-{
+namespace {
using namespace detail;
// for sorting tests by file/line
int fileOrderComparator(const void* a, const void* b) {
@@ -3857,8 +3817,7 @@
}
} // namespace
-namespace detail
-{
+namespace detail {
// used by the macros for registering tests
int regTest(const TestCase& tc) {
getRegisteredTests().insert(tc);
@@ -3973,8 +3932,7 @@
void ContextScope::stringify(std::ostream* s) const { contextBuilder.stringify(s); }
} // namespace detail
-namespace
-{
+namespace {
using namespace detail;
#if !defined(DOCTEST_CONFIG_POSIX_SIGNALS) && !defined(DOCTEST_CONFIG_WINDOWS_SEH)
struct FatalConditionHandler
@@ -4131,8 +4089,7 @@
#include <sys/sysctl.h>
#endif // DOCTEST_PLATFORM_MAC
-namespace
-{
+namespace {
using namespace detail;
#ifdef DOCTEST_PLATFORM_MAC
// The following function is taken directly from the following technical note:
@@ -4206,8 +4163,7 @@
}
#endif // DOCTEST_CONFIG_POSIX_SIGNALS || DOCTEST_CONFIG_WINDOWS_SEH
} // namespace
-namespace detail
-{
+namespace detail {
ResultBuilder::ResultBuilder(assertType::Enum at, const char* file, int line, const char* expr,
const char* exception_type) {
m_test_case = g_contextState->currentTest;
@@ -4293,8 +4249,7 @@
MessageBuilder::~MessageBuilder() { freeStream(m_stream); }
} // namespace detail
-namespace
-{
+namespace {
using namespace detail;
struct ConsoleReporter : public IReporter
{
diff --git a/doctest/parts/doctest_fwd.h b/doctest/parts/doctest_fwd.h
index 8fd284a..eb354e3 100644
--- a/doctest/parts/doctest_fwd.h
+++ b/doctest/parts/doctest_fwd.h
@@ -392,8 +392,7 @@
// so the <iosfwd> header is used - also it is very light and doesn't drag a ton of stuff
#include <iosfwd>
#else // _LIBCPP_VERSION
-namespace std
-{
+namespace std {
template <class charT>
struct char_traits;
template <>
@@ -407,8 +406,7 @@
#ifdef _LIBCPP_VERSION
#include <cstddef>
#else // _LIBCPP_VERSION
-namespace std
-{
+namespace std {
typedef decltype(nullptr) nullptr_t;
}
#endif // _LIBCPP_VERSION
@@ -417,10 +415,8 @@
#include <type_traits>
#endif // DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS
-namespace doctest
-{
-namespace detail
-{
+namespace doctest {
+namespace detail {
// the function type this library works with
typedef void (*funcType)();
} // namespace detail
@@ -511,8 +507,7 @@
DOCTEST_INTERFACE std::ostream& operator<<(std::ostream& s, const String& in);
-namespace Color
-{
+namespace Color {
enum Enum
{
None = 0,
@@ -535,8 +530,7 @@
DOCTEST_INTERFACE std::ostream& operator<<(std::ostream& s, Color::Enum code);
} // namespace Color
-namespace assertType
-{
+namespace assertType {
enum Enum
{
// macro traits
@@ -768,8 +762,7 @@
DOCTEST_DELETE_COPIES(ContextOptions);
};
-namespace detail
-{
+namespace detail {
#if defined(DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING) || defined(DOCTEST_CONFIG_INCLUDE_TYPE_TRAITS)
template <bool CONDITION, typename TYPE = void>
struct enable_if
@@ -788,8 +781,7 @@
// to silence the warning "-Wzero-as-null-pointer-constant" only for gcc 5 for the Approx template ctor - pragmas don't work for it...
inline void* getNull() { return 0; }
- namespace has_insertion_operator_impl
- {
+ namespace has_insertion_operator_impl {
typedef char no;
typedef char yes[2];
@@ -1000,8 +992,7 @@
#if !defined(DOCTEST_CONFIG_DISABLE)
-namespace detail
-{
+namespace detail {
// clang-format off
#ifdef DOCTEST_CONFIG_TREAT_CHAR_STAR_AS_STRING
template<class T> struct decay_array { typedef T type; };
@@ -1307,8 +1298,7 @@
DOCTEST_INTERFACE int regTest(const TestCase& tc);
DOCTEST_INTERFACE int setTestSuite(const TestSuite& ts);
- namespace binaryAssertComparison
- {
+ namespace binaryAssertComparison {
enum Enum
{
eq = 0,
@@ -1369,8 +1359,7 @@
void react() const;
};
- namespace assertAction
- {
+ namespace assertAction {
enum Enum
{
nothing = 0,
@@ -1694,13 +1683,11 @@
// in a separate namespace outside of doctest because the DOCTEST_TEST_SUITE macro
// introduces an anonymous namespace in which getCurrentTestSuite gets overridden
-namespace doctest_detail_test_suite_ns
-{
+namespace doctest_detail_test_suite_ns {
DOCTEST_INTERFACE doctest::detail::TestSuite& getCurrentTestSuite();
} // namespace doctest_detail_test_suite_ns
-namespace doctest
-{
+namespace doctest {
#else // DOCTEST_CONFIG_DISABLE
template <typename T>
int registerExceptionTranslator(String (*)(T)) {
@@ -1710,8 +1697,7 @@
DOCTEST_INTERFACE bool isRunningInTest();
-namespace detail
-{
+namespace detail {
struct ContextState;
} // namespace detail
@@ -1741,8 +1727,7 @@
int run();
};
-namespace TestCaseFailureReason
-{
+namespace TestCaseFailureReason {
enum Enum
{
None = 0,
@@ -1857,8 +1842,7 @@
DOCTEST_GLOBAL_NO_WARNINGS_END()
#define DOCTEST_IMPLEMENT_FIXTURE(der, base, func, decorators) \
- namespace \
- { \
+ namespace { \
struct der : public base \
{ \
void f(); \
@@ -1892,10 +1876,7 @@
return "<" #__VA_ARGS__ ">"; \
}
#define DOCTEST_TYPE_TO_STRING(...) \
- namespace doctest \
- { \
- namespace detail \
- { \
+ namespace doctest { namespace detail { \
DOCTEST_TYPE_TO_STRING_IMPL(__VA_ARGS__) \
} \
} \
@@ -1973,10 +1954,7 @@
// for grouping tests in test suites by using code blocks
#define DOCTEST_TEST_SUITE_IMPL(decorators, ns_name) \
- namespace ns_name \
- { \
- namespace doctest_detail_test_suite_ns \
- { \
+ namespace ns_name { namespace doctest_detail_test_suite_ns { \
static DOCTEST_NOINLINE doctest::detail::TestSuite& getCurrentTestSuite() { \
static doctest::detail::TestSuite data; \
static bool inited = false; \
@@ -2337,8 +2315,7 @@
#else // DOCTEST_CONFIG_DISABLE
#define DOCTEST_IMPLEMENT_FIXTURE(der, base, func, name) \
- namespace \
- { \
+ namespace { \
template <typename DOCTEST_UNUSED_TEMPLATE_TYPE> \
struct der : public base \
{ void f(); }; \
@@ -2627,10 +2604,7 @@
DOCTEST_TEST_SUITE_END();
// add stringification for primitive/fundamental types
-namespace doctest
-{
-namespace detail
-{
+namespace doctest { namespace detail {
DOCTEST_TYPE_TO_STRING_IMPL(bool)
DOCTEST_TYPE_TO_STRING_IMPL(float)
DOCTEST_TYPE_TO_STRING_IMPL(double)
@@ -2647,8 +2621,7 @@
DOCTEST_TYPE_TO_STRING_IMPL(unsigned long int)
DOCTEST_TYPE_TO_STRING_IMPL(long long int)
DOCTEST_TYPE_TO_STRING_IMPL(unsigned long long int)
-} // namespace detail
-} // namespace doctest
+}} // namespace doctest::detail
#endif // DOCTEST_CONFIG_DISABLE
diff --git a/doctest/parts/doctest_impl.h b/doctest/parts/doctest_impl.h
index dd49942..c80655d 100644
--- a/doctest/parts/doctest_impl.h
+++ b/doctest/parts/doctest_impl.h
@@ -125,12 +125,10 @@
#define DOCTEST_BRANCH_ON_DISABLED(if_disabled, if_not_disabled) if_not_disabled
#endif // DOCTEST_CONFIG_DISABLE
-namespace doctest
-{
+namespace doctest {
void my_memcpy(void* dest, const void* src, unsigned num) { memcpy(dest, src, num); }
-namespace
-{
+namespace {
using namespace detail;
// case insensitive strcmp
int stricmp(const char* a, const char* b) {
@@ -176,8 +174,7 @@
};
} // namespace
-namespace detail
-{
+namespace detail {
void my_memcpy(void* dest, const void* src, unsigned num) { memcpy(dest, src, num); }
String rawMemoryToString(const void* object, unsigned size) {
@@ -404,13 +401,11 @@
std::ostream& operator<<(std::ostream& s, const String& in) { return s << in.c_str(); }
-namespace
-{
+namespace {
void color_to_stream(std::ostream&, Color::Enum) DOCTEST_BRANCH_ON_DISABLED({}, ;)
} // namespace
-namespace Color
-{
+namespace Color {
std::ostream& operator<<(std::ostream& s, Color::Enum code) {
color_to_stream(s, code);
return s;
@@ -649,8 +644,7 @@
} // namespace doctest
#ifdef DOCTEST_CONFIG_DISABLE
-namespace doctest
-{
+namespace doctest {
bool isRunningInTest() { return false; }
Context::Context(int, const char* const*) {}
Context::~Context() = default;
@@ -734,8 +728,7 @@
#endif // DOCTEST_PLATFORM_WINDOWS
-namespace doctest_detail_test_suite_ns
-{
+namespace doctest_detail_test_suite_ns {
// holds the current test suite
doctest::detail::TestSuite& getCurrentTestSuite() {
static doctest::detail::TestSuite data;
@@ -743,10 +736,8 @@
}
} // namespace doctest_detail_test_suite_ns
-namespace doctest
-{
-namespace
-{
+namespace doctest {
+namespace {
using namespace detail;
typedef std::map<std::pair<int, String>, IReporter*> reporterMap;
reporterMap& getReporters() {
@@ -760,8 +751,7 @@
#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
}
} // namespace
-namespace detail
-{
+namespace detail {
#define DOCTEST_ITERATE_THROUGH_REPORTERS(function, args) \
for(auto& curr_rep : g_contextState->reporters_currently_used) \
curr_rep->function(args)
@@ -786,8 +776,7 @@
}
} // namespace detail
-namespace
-{
+namespace {
using namespace detail;
// matching of a string against a wildcard mask (case sensitivity configurable) taken from
// https://www.codeproject.com/Articles/1088/Wildcard-string-compare-globbing
@@ -892,8 +881,7 @@
Timer g_timer;
} // namespace
-namespace detail
-{
+namespace detail {
const ContextOptions* getContextOptions() { return g_contextState; }
Subcase::Subcase(const char* name, const char* file, int line)
@@ -1030,8 +1018,7 @@
return m_template_id < other.m_template_id;
}
} // namespace detail
-namespace
-{
+namespace {
using namespace detail;
// for sorting tests by file/line
int fileOrderComparator(const void* a, const void* b) {
@@ -1190,8 +1177,7 @@
}
} // namespace
-namespace detail
-{
+namespace detail {
// used by the macros for registering tests
int regTest(const TestCase& tc) {
getRegisteredTests().insert(tc);
@@ -1306,8 +1292,7 @@
void ContextScope::stringify(std::ostream* s) const { contextBuilder.stringify(s); }
} // namespace detail
-namespace
-{
+namespace {
using namespace detail;
#if !defined(DOCTEST_CONFIG_POSIX_SIGNALS) && !defined(DOCTEST_CONFIG_WINDOWS_SEH)
struct FatalConditionHandler
@@ -1464,8 +1449,7 @@
#include <sys/sysctl.h>
#endif // DOCTEST_PLATFORM_MAC
-namespace
-{
+namespace {
using namespace detail;
#ifdef DOCTEST_PLATFORM_MAC
// The following function is taken directly from the following technical note:
@@ -1539,8 +1523,7 @@
}
#endif // DOCTEST_CONFIG_POSIX_SIGNALS || DOCTEST_CONFIG_WINDOWS_SEH
} // namespace
-namespace detail
-{
+namespace detail {
ResultBuilder::ResultBuilder(assertType::Enum at, const char* file, int line, const char* expr,
const char* exception_type) {
m_test_case = g_contextState->currentTest;
@@ -1626,8 +1609,7 @@
MessageBuilder::~MessageBuilder() { freeStream(m_stream); }
} // namespace detail
-namespace
-{
+namespace {
using namespace detail;
struct ConsoleReporter : public IReporter
{