Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
ah-errors.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
32
86# ifndef AH_ERRORS_H
87# define AH_ERRORS_H
88
89# include <stdexcept>
90# include <sstream>
91
92namespace Aleph
93{
94
105 template<class E>
107 {
116 [[noreturn]] int operator,(const std::ostream &s)
117 {
118 if (const auto * oss = dynamic_cast<const std::ostringstream *>(&s))
119 throw E(oss->str());
120
121 if (const auto * ss = dynamic_cast<const std::stringstream *>(&s))
122 throw E(ss->str());
123
124 throw E("Unknown stream type in Aleph::ExceptionBuilder");
125 }
126 };
127
128}
129
130// ============================================================================
131// WARNING MACROS
132// ============================================================================
133
146#define ah_warning_unless(out, C) \
147 if (not (C)) \
148 [[unlikely]](out) << "WARNING (" << __FILE__ << ":" << __LINE__ << ") | "
149
162#define ah_warning_if(out, C) \
163 if (C) \
164 [[unlikely]](out) << "WARNING (" << __FILE__ << ":" << __LINE__ << ") | "
165
177#define ah_warning(out) \
178 (out) << "WARNING (" << __FILE__ << ":" << __LINE__ << ") | "
179
180// ============================================================================
181// EXCEPTION MACROS: RANGE_ERROR
182// ============================================================================
183
196#define ah_range_error_unless(C) \
197 if (not (C)) \
198 [[unlikely]]Aleph::ExceptionBuilder<std::range_error>(), \
199 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
200
212#define ah_range_error_if(C) \
213 if (C) \
214 [[unlikely]]Aleph::ExceptionBuilder<std::range_error>(), \
215 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
216
228#define ah_range_error() \
229 Aleph::ExceptionBuilder<std::range_error>(), \
230 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
231
232#define ah_range_error_if_constexpr(C) \
233 if constexpr (C) \
234 ah_range_error()
235
236#define ah_range_error_unless_constexpr(C) \
237 if constexpr (not (C)) \
238 ah_range_error()
239
240// ============================================================================
241// EXCEPTION MACROS: RUNTIME_ERROR
242// ============================================================================
243
255#define ah_runtime_error_unless(C) \
256 if (not (C)) \
257 [[unlikely]]Aleph::ExceptionBuilder<std::runtime_error>(), \
258 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
259
271#define ah_runtime_error_if(C) \
272 if (C) \
273 [[unlikely]]Aleph::ExceptionBuilder<std::runtime_error>(), \
274 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
275
287#define ah_runtime_error() \
288 Aleph::ExceptionBuilder<std::runtime_error>(), \
289 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
290
291#define ah_runtime_error_if_constexpr(C) \
292 if constexpr (C) \
293 ah_runtime_error()
294
295#define ah_runtime_error_unless_constexpr(C) \
296 if constexpr (not (C)) \
297 ah_runtime_error()
298
299// ============================================================================
300// EXCEPTION MACROS: LOGIC_ERROR
301// ============================================================================
302
314#define ah_logic_error_unless(C) \
315 if (not (C)) \
316 [[unlikely]]Aleph::ExceptionBuilder<std::logic_error>(), \
317 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
318
330#define ah_logic_error_if(C) \
331 if (C) \
332 [[unlikely]]Aleph::ExceptionBuilder<std::logic_error>(), \
333 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
334
346#define ah_logic_error() \
347 Aleph::ExceptionBuilder<std::logic_error>(), \
348 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
349
350#define ah_logic_error_if_constexpr(C) \
351 if constexpr (C) \
352 ah_logic_error()
353
354#define ah_logic_error_unless_constexpr(C) \
355 if constexpr (not (C)) \
356 ah_logic_error()
357
358// ============================================================================
359// EXCEPTION MACROS: UNDERFLOW_ERROR
360// ============================================================================
361
373#define ah_underflow_error_if(C) \
374 if (C) \
375 [[unlikely]]Aleph::ExceptionBuilder<std::underflow_error>(), \
376 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
377
389#define ah_underflow_error_unless(C) \
390 if (not (C)) \
391 [[unlikely]]Aleph::ExceptionBuilder<std::underflow_error>(), \
392 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
393
405#define ah_underflow_error() \
406 Aleph::ExceptionBuilder<std::underflow_error>(), \
407 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
408
409#define ah_underflow_error_if_constexpr(C) \
410 if constexpr (C) \
411 ah_underflow_error()
412
413#define ah_underflow_error_unless_constexpr(C) \
414 if constexpr (not (C)) \
415 ah_underflow_error()
416
417// ============================================================================
418// EXCEPTION MACROS: BAD_ALLOC (NO MESSAGE)
419// ============================================================================
420
426#define ah_bad_alloc() \
427 do { [[unlikely]] throw std::bad_alloc(); } while (false)
428
434#define ah_bad_alloc_if(C) \
435 do { if (C) [[unlikely]] throw std::bad_alloc(); } while (false)
436
442#define ah_bad_alloc_unless(C) \
443 do { if (!(C)) [[unlikely]] throw std::bad_alloc(); } while (false)
444
445#define ah_bad_alloc_if_constexpr(C) \
446 if constexpr (C) \
447 ah_bad_alloc()
448
449#define ah_bad_alloc_unless_constexpr(C) \
450 if constexpr (not (C)) \
451 ah_bad_alloc()
452
453// ============================================================================
454// EXCEPTION MACROS: OVERFLOW_ERROR
455// ============================================================================
456
468#define ah_overflow_error_if(C) \
469 if (C) \
470 [[unlikely]]Aleph::ExceptionBuilder<std::overflow_error>(), \
471 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
472
484#define ah_overflow_error_unless(C) \
485 if (not (C)) \
486 [[unlikely]]Aleph::ExceptionBuilder<std::overflow_error>(), \
487 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
488
500#define ah_overflow_error() \
501 Aleph::ExceptionBuilder<std::overflow_error>(), \
502 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
503
504#define ah_overflow_error_if_constexpr(C) \
505 if constexpr (C) \
506 ah_overflow_error()
507
508#define ah_overflow_error_unless_constexpr(C) \
509 if constexpr (not (C)) \
510 ah_overflow_error()
511
512// ============================================================================
513// EXCEPTION MACROS: DOMAIN_ERROR
514// ============================================================================
515
527#define ah_domain_error_if(C) \
528 if (C) \
529 [[unlikely]]Aleph::ExceptionBuilder<std::domain_error>(), \
530 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
531
543#define ah_domain_error_unless(C) \
544 if (not (C)) \
545 [[unlikely]]Aleph::ExceptionBuilder<std::domain_error>(), \
546 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
547
559#define ah_domain_error() \
560 Aleph::ExceptionBuilder<std::domain_error>(), \
561 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
562#define ah_domain_error_if_constexpr(C) \
563 if constexpr (C) \
564 ah_domain_error()
565#define ah_domain_error_unless_constexpr(C) \
566 if constexpr (not (C)) \
567 ah_domain_error()
568
569// ============================================================================
570// EXCEPTION MACROS: OUT_OF_RANGE
571// ============================================================================
572
584#define ah_out_of_range_error_if(C) \
585 if (C) \
586 [[unlikely]]Aleph::ExceptionBuilder<std::out_of_range>(), \
587 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
588
600#define ah_out_of_range_error_unless(C) \
601 if (not (C)) \
602 [[unlikely]]Aleph::ExceptionBuilder<std::out_of_range>(), \
603 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
604
616#define ah_out_of_range_error() \
617 Aleph::ExceptionBuilder<std::out_of_range>(), \
618 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
619
620#define ah_out_of_range_error_if_constexpr(C) \
621 if constexpr (C) \
622 ah_out_of_range_error()
623
624#define ah_out_of_range_error_unless_constexpr(C) \
625 if constexpr (not (C)) \
626 ah_out_of_range_error()
627
628// ============================================================================
629// EXCEPTION MACROS: INVALID_ARGUMENT
630// ============================================================================
631
644#define ah_invalid_argument_if(C) \
645 if (C) \
646 [[unlikely]]Aleph::ExceptionBuilder<std::invalid_argument>(), \
647 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
648
660#define ah_invalid_argument_unless(C) \
661 if (not (C)) \
662 [[unlikely]]Aleph::ExceptionBuilder<std::invalid_argument>(), \
663 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
664
676#define ah_invalid_argument() \
677 Aleph::ExceptionBuilder<std::invalid_argument>(), \
678 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
679
680#define ah_invalid_argument_if_constexpr(C) \
681 if constexpr (C) \
682 ah_invalid_argument()
683
684#define ah_invalid_argument_unless_constexpr(C) \
685 if constexpr (not (C)) \
686 ah_invalid_argument()
687
688// ============================================================================
689// EXCEPTION MACROS: LENGTH_ERROR
690// ============================================================================
691
703#define ah_length_error_if(C) \
704 if (C) \
705 [[unlikely]]Aleph::ExceptionBuilder<std::length_error>(), \
706 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
707
719#define ah_length_error_unless(C) \
720 if (not (C)) \
721 [[unlikely]]Aleph::ExceptionBuilder<std::length_error>(), \
722 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
723
735#define ah_length_error() \
736 Aleph::ExceptionBuilder<std::length_error>(), \
737 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
738
739#define ah_length_error_if_constexpr(C) \
740 if constexpr (C) \
741 ah_length_error()
742
743#define ah_length_error_unless_constexpr(C) \
744 if constexpr (not (C)) \
745 ah_length_error()
746
747// ============================================================================
748// FATAL ERROR MACRO
749// ============================================================================
750
764#define ah_fatal_error() \
765 Aleph::ExceptionBuilder<std::runtime_error>(), \
766 std::ostringstream() << "(" << __FILE__ << ":" << __LINE__ << ") | "
767
768# endif
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
Exception constructor with formatted message.
Definition ah-errors.H:107
int operator,(const std::ostream &s)
Comma operator that throws the exception with the constructed message.
Definition ah-errors.H:116