Line data Source code
1 : // Copyright (c) 2022 Made to Order Software Corp. All Rights Reserved
2 : //
3 : // https://snapwebsites.org/project/snapdev
4 : // contact@m2osw.com
5 : //
6 : // This program is free software; you can redistribute it and/or modify
7 : // it under the terms of the GNU General Public License as published by
8 : // the Free Software Foundation; either version 2 of the License, or
9 : // (at your option) any later version.
10 : //
11 : // This program is distributed in the hope that it will be useful,
12 : // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 : // GNU General Public License for more details.
15 : //
16 : // You should have received a copy of the GNU General Public License along
17 : // with this program; if not, write to the Free Software Foundation, Inc.,
18 : // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 : #pragma once
20 :
21 : // self
22 : //
23 : #include <snapdev/not_used.h>
24 :
25 :
26 : // C++ lib
27 : //
28 : #include <iostream>
29 :
30 :
31 :
32 : namespace snapdev
33 : {
34 :
35 : /** \brief A debug/non-debug assert() which can include side effects.
36 : *
37 : * This function is safe to use without any special protection. The
38 : * expression to verify will be optimized out, except for any part which
39 : * may have side effects.
40 : *
41 : * \param[in] test_result The value to be tested, if true, the assert passes.
42 : * \param[in] ... args Arguments to pass to std::cerr for a user defined
43 : * message.
44 : */
45 : template<typename ... Args>
46 1 : void SAFE_ASSERT(bool test_result, Args && ... args)
47 : {
48 : #ifdef _DEBUG
49 1 : if(!test_result)
50 : {
51 0 : (std::cerr << ... << args);
52 0 : std::cerr << std::endl;
53 0 : std::terminate();
54 : }
55 : #else
56 : NOT_USED(test_result, args...);
57 : #endif
58 1 : }
59 :
60 :
61 :
62 : } // snap namespacedev
63 : // vim: ts=4 sw=4 et
|