@@ -196,33 +196,33 @@ class out {
196
196
#define CPP2_SOURCE_LOCATION_PARAM , std::source_location where
197
197
#define CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT , std::source_location where = std::source_location::current()
198
198
#define CPP2_SOURCE_LOCATION_PARAM_SOLO std::source_location where
199
- // #define CPP2_SOURCE_LOCATION_PARAM_SOLO_ANON std::source_location
200
199
#define CPP2_SOURCE_LOCATION_ARG , where
201
- // #define CPP2_SOURCE_LOCATION_ARG_SOLO where
202
200
#else
203
201
#define CPP2_SOURCE_LOCATION_PARAM
204
202
#define CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT
205
203
#define CPP2_SOURCE_LOCATION_PARAM_SOLO
206
- // #define CPP2_SOURCE_LOCATION_PARAM_SOLO_ANON
207
204
#define CPP2_SOURCE_LOCATION_ARG
208
- // #define CPP2_SOURCE_LOCATION_ARG_SOLO
209
205
#endif
210
206
207
+ // For C++23: make this std::string_view and drop the macro
208
+ // Before C++23 std::string_view was not guaranteed to be trivially copyable,
209
+ // and so in<T> will pass it by const& and really it should be by value
210
+ #define CPP2_MESSAGE_PARAM char const *
211
211
212
212
class contract_group {
213
213
public:
214
- using handler = void (*)(const char * msg CPP2_SOURCE_LOCATION_PARAM) noexcept ;
214
+ using handler = void (*)(CPP2_MESSAGE_PARAM msg CPP2_SOURCE_LOCATION_PARAM) noexcept ;
215
215
216
216
constexpr contract_group (handler h = nullptr ) : reporter(h) { }
217
217
constexpr auto set_handler (handler h) -> handler { assert (h); auto old = reporter; reporter = h; return old; }
218
218
constexpr auto get_handler () const -> handler { return reporter; }
219
- constexpr auto expects (bool b, const char * msg = " " CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT)
219
+ constexpr auto expects (bool b, CPP2_MESSAGE_PARAM msg = " " CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT)
220
220
-> void { if (!b) reporter (msg CPP2_SOURCE_LOCATION_ARG); }
221
221
private:
222
222
handler reporter;
223
223
};
224
224
225
- [[noreturn]] auto report_and_terminate (std::string_view group, const char * msg = " " CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) noexcept -> void {
225
+ [[noreturn]] auto report_and_terminate (std::string_view group, CPP2_MESSAGE_PARAM msg = " " CPP2_SOURCE_LOCATION_PARAM_WITH_DEFAULT) noexcept -> void {
226
226
std::cerr
227
227
#ifdef CPP2_USE_SOURCE_LOCATION
228
228
<< where.file_name () << " 2("
@@ -238,27 +238,27 @@ class contract_group {
238
238
}
239
239
240
240
auto inline Default = contract_group(
241
- [](const char * msg CPP2_SOURCE_LOCATION_PARAM)noexcept {
241
+ [](CPP2_MESSAGE_PARAM msg CPP2_SOURCE_LOCATION_PARAM)noexcept {
242
242
report_and_terminate (" Contract" , msg CPP2_SOURCE_LOCATION_ARG);
243
243
}
244
244
);
245
245
auto inline Bounds = contract_group(
246
- [](const char * msg CPP2_SOURCE_LOCATION_PARAM)noexcept {
246
+ [](CPP2_MESSAGE_PARAM msg CPP2_SOURCE_LOCATION_PARAM)noexcept {
247
247
report_and_terminate (" Bounds safety" , msg CPP2_SOURCE_LOCATION_ARG);
248
248
}
249
249
);
250
250
auto inline Null = contract_group(
251
- [](const char * msg CPP2_SOURCE_LOCATION_PARAM)noexcept {
251
+ [](CPP2_MESSAGE_PARAM msg CPP2_SOURCE_LOCATION_PARAM)noexcept {
252
252
report_and_terminate (" Null safety" , msg CPP2_SOURCE_LOCATION_ARG);
253
253
}
254
254
);
255
255
auto inline Type = contract_group(
256
- [](const char * msg CPP2_SOURCE_LOCATION_PARAM)noexcept {
256
+ [](CPP2_MESSAGE_PARAM msg CPP2_SOURCE_LOCATION_PARAM)noexcept {
257
257
report_and_terminate (" Type safety" , msg CPP2_SOURCE_LOCATION_ARG);
258
258
}
259
259
);
260
260
auto inline Testing = contract_group(
261
- [](const char * msg CPP2_SOURCE_LOCATION_PARAM)noexcept {
261
+ [](CPP2_MESSAGE_PARAM msg CPP2_SOURCE_LOCATION_PARAM)noexcept {
262
262
report_and_terminate (" Testing" , msg CPP2_SOURCE_LOCATION_ARG);
263
263
}
264
264
);
0 commit comments