forked from gsl-lite/gsl-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgsl-lite.t.hpp
107 lines (81 loc) · 2.85 KB
/
gsl-lite.t.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2015 by Martin Moene
//
// gsl-lite is based on GSL: Guidelines Support Library.
// For more information see https://github.com/martinmoene/gsl-lite
//
// This code is licensed under the MIT License (MIT).
//
#pragma once
#ifndef GSL_TEST_GSL_LITE_HPP_INCLUDED
#define GSL_TEST_GSL_LITE_HPP_INCLUDED
// Select GSL Lite for VC6 if compiling with VC6:
#if defined(_MSC_VER) && _MSC_VER < 1300
# include "gsl/gsl-lite-vc6.hpp"
#else
# include "gsl/gsl-lite.hpp"
#endif
// Limit C++ Core Guidelines checking to GSL Lite:
#if defined(_MSC_VER) && _MSC_VER >= 1910
# include <CppCoreCheck/warnings.h>
# pragma warning(disable: ALL_CPPCORECHECK_WARNINGS)
#endif
// Compiler warning suppression for usage of lest:
#ifdef __clang__
# pragma clang diagnostic ignored "-Wstring-conversion"
# pragma clang diagnostic ignored "-Wunused-parameter"
# pragma clang diagnostic ignored "-Wunused-template"
# pragma clang diagnostic ignored "-Wunused-function"
# pragma clang diagnostic ignored "-Wunused-member-function"
#elif defined __GNUC__
# pragma GCC diagnostic ignored "-Wunused-parameter"
# pragma GCC diagnostic ignored "-Wunused-function"
#endif
namespace lest {
// These functions cannot be found via ADL, so we have to define them before including lest.
#if gsl_HAVE( ARRAY )
template< typename T, std::size_t N >
inline std::ostream & operator<<( std::ostream & os, std::array<T,N> const & a )
{
return os << std::hex << "[std::array[" << N << "]";
}
#endif
#if gsl_HAVE( WCHAR )
// We do this with a loop and explicit casts to avoid warnings about implicit narrowing casts (which we don't care about because we don't have to handle non-ASCII strings in the tests).
inline std::string narrowString( std::wstring const & str )
{
std::string result(str.size(), '\0');
for (std::size_t i = 0, n = str.size(); i != n; ++i)
{
result[i] = static_cast<char>(str[i]);
}
return result;
}
inline std::ostream & operator<<( std::ostream & os, std::wstring const & text )
{
return os << narrowString( text );
}
#endif // gsl_HAVE( WCHAR )
} // namespace lest
#include "lest_cpp03.hpp"
#define CASE( name ) lest_CASE( specification(), name )
extern lest::tests & specification();
namespace gsl {
inline const void * nullptr_void() { return gsl_nullptr; }
// use operator<< instead of to_string() overload;
// see http://stackoverflow.com/a/10651752/437272
inline std::ostream & operator<<( std::ostream & os, byte b )
{
return os << std::hex << "0x" << to_integer<int>(b);
}
template< typename T >
inline std::ostream & operator<<( std::ostream & os, span<T> s )
{
return os << "[", std::copy( s.begin(), s.end(), std::ostream_iterator<T>(os, ",") ), os << "]";
}
} // namespace gsl
inline void suppress_warning_unused_template_ensure_sentinel()
{
(void) gsl::ensure_z( "zero-terminated" );
}
#endif // GSL_TEST_GSL_LITE_HPP_INCLUDED
// end of file