@@ -74,8 +74,10 @@ class static_variant {
74
74
75
75
void init_from_tag (tag_type tag)
76
76
{
77
- FC_ASSERT ( tag >= 0 );
78
- FC_ASSERT ( static_cast <size_t >(tag) < count () );
77
+ FC_ASSERT ( tag >= 0 , " Unable to init with a negative tag '${tag}'" , (" tag" ,tag) );
78
+ FC_ASSERT ( static_cast <size_t >(tag) < count (),
79
+ " Unable to init with tag '${tag}' when the number of supported tags is ${count}" ,
80
+ (" tag" ,tag) (" count" ,count ()) );
79
81
_tag = tag;
80
82
typelist::runtime::dispatch (list (), tag, [this ](auto t) {
81
83
using T = typename decltype (t)::type;
@@ -235,15 +237,19 @@ class static_variant {
235
237
if (_tag == typelist::index_of<list, X>()) {
236
238
return *reinterpret_cast <X*>(storage.data ());
237
239
} else {
238
- FC_THROW_EXCEPTION ( fc::assert_exception, " static_variant does not contain a value of type ${t}" , (" t" ,fc::get_typename<X>::name ()) );
240
+ FC_THROW_EXCEPTION ( fc::assert_exception,
241
+ " static_variant does not contain a value of type ${t}" ,
242
+ (" t" ,fc::get_typename<X>::name ()) );
239
243
}
240
244
}
241
245
template <typename X, typename = type_in_typelist<X>>
242
246
const X& get () const {
243
247
if (_tag == typelist::index_of<list, X>()) {
244
248
return *reinterpret_cast <const X*>(storage.data ());
245
249
} else {
246
- FC_THROW_EXCEPTION ( fc::assert_exception, " static_variant does not contain a value of type ${t}" , (" t" ,fc::get_typename<X>::name ()) );
250
+ FC_THROW_EXCEPTION ( fc::assert_exception,
251
+ " static_variant does not contain a value of type ${t}" ,
252
+ (" t" ,fc::get_typename<X>::name ()) );
247
253
}
248
254
}
249
255
template <typename visitor>
@@ -269,7 +275,9 @@ class static_variant {
269
275
template <typename visitor>
270
276
static typename visitor::result_type visit ( tag_type tag, visitor& v, void * data )
271
277
{
272
- FC_ASSERT ( tag >= 0 && static_cast <size_t >(tag) < count (), " Unsupported type ${tag}!" , (" tag" ,tag) );
278
+ FC_ASSERT ( tag >= 0 && static_cast <size_t >(tag) < count (),
279
+ " Unsupported type '${tag}', the number of supported types is ${count}! " ,
280
+ (" tag" ,tag) (" count" ,count ()) );
273
281
return typelist::runtime::dispatch (list (), tag, [&v, data](auto t) {
274
282
return v (*reinterpret_cast <typename decltype (t)::type*>(data));
275
283
});
@@ -278,7 +286,9 @@ class static_variant {
278
286
template <typename visitor>
279
287
static typename visitor::result_type visit ( tag_type tag, const visitor& v, void * data )
280
288
{
281
- FC_ASSERT ( tag >= 0 && static_cast <size_t >(tag) < count (), " Unsupported type ${tag}!" , (" tag" ,tag) );
289
+ FC_ASSERT ( tag >= 0 && static_cast <size_t >(tag) < count (),
290
+ " Unsupported type '${tag}', the number of supported types is ${count}! " ,
291
+ (" tag" ,tag) (" count" ,count ()) );
282
292
return typelist::runtime::dispatch (list (), tag, [&v, data](auto t) {
283
293
return v (*reinterpret_cast <typename decltype (t)::type*>(data));
284
294
});
@@ -287,7 +297,9 @@ class static_variant {
287
297
template <typename visitor>
288
298
static typename visitor::result_type visit ( tag_type tag, visitor& v, const void * data )
289
299
{
290
- FC_ASSERT ( tag >= 0 && static_cast <size_t >(tag) < count (), " Unsupported type ${tag}!" , (" tag" ,tag) );
300
+ FC_ASSERT ( tag >= 0 && static_cast <size_t >(tag) < count (),
301
+ " Unsupported type '${tag}', the number of supported types is ${count}! " ,
302
+ (" tag" ,tag) (" count" ,count ()) );
291
303
return typelist::runtime::dispatch (list (), tag, [&v, data](auto t) {
292
304
return v (*reinterpret_cast <const typename decltype (t)::type*>(data));
293
305
});
@@ -296,16 +308,20 @@ class static_variant {
296
308
template <typename visitor>
297
309
static typename visitor::result_type visit ( tag_type tag, const visitor& v, const void * data )
298
310
{
299
- FC_ASSERT ( tag >= 0 && static_cast <size_t >(tag) < count (), " Unsupported type ${tag}!" , (" tag" ,tag) );
311
+ FC_ASSERT ( tag >= 0 && static_cast <size_t >(tag) < count (),
312
+ " Unsupported type '${tag}', the number of supported types is ${count}! " ,
313
+ (" tag" ,tag) (" count" ,count ()) );
300
314
return typelist::runtime::dispatch (list (), tag, [&v, data](auto t) {
301
315
return v (*reinterpret_cast <const typename decltype (t)::type*>(data));
302
316
});
303
317
}
304
318
305
319
static constexpr size_t count () { return typelist::length<list>(); }
306
320
void set_which ( tag_type tag ) {
307
- FC_ASSERT ( tag >= 0 );
308
- FC_ASSERT ( static_cast <size_t >(tag) < count () );
321
+ FC_ASSERT ( tag >= 0 , " Unable to set a negative tag '${tag}'" , (" tag" ,tag) );
322
+ FC_ASSERT ( static_cast <size_t >(tag) < count (),
323
+ " Unable to set tag '${tag}' when the number of supported tags is ${count}" ,
324
+ (" tag" ,tag) (" count" ,count ()) );
309
325
clean ();
310
326
init_from_tag (tag);
311
327
}
0 commit comments