-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved to having just 2 assert macros from 3
- Loading branch information
Showing
18 changed files
with
68 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
|
||
|
||
#ifndef BIT_DEBUG | ||
#define BIT_DEBUG | ||
#endif | ||
#include <bit/bit.h> | ||
int main() | ||
{ | ||
// lambda: Turns the degree of a polynomial into a string. | ||
auto deg = [](auto& p) { return p.degree() == bit::polynomial<>::ndeg ? "NONE" : std::format("{}", p.degree()); }; | ||
|
||
auto p0 = bit::polynomial<>::random(0); | ||
std::cout << std::format("p0(x) = {} has degree: {}.\n", p0, deg(p0)); | ||
|
||
auto p1 = bit::polynomial<>::random(7); | ||
std::cout << std::format("p0(x) = {} has degree: {}.\n", p1, deg(p1)); | ||
|
||
auto p2 = bit::polynomial<>::random(7, 0.9); | ||
std::cout << std::format("p0(x) = {} has degree: {}.\n", p2, deg(p2)); | ||
std::size_t n = 12; // <1> | ||
bit::vector<> v(n); | ||
v.set(n); // <2> | ||
std::cout << v << "\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/// @brief Three replacements for the standard `assert(condition)` macro that add an informational message. | ||
/// @brief Two replacements for the standard `assert(condition)` macro that add an informational message. | ||
/// @link https://nessan.github.io/bit | ||
/// SPDX-FileCopyrightText: 2024 Nessan Fitzmaurice <[email protected]> | ||
/// SPDX-License-Identifier: MIT | ||
|
@@ -9,32 +9,21 @@ | |
#include <iostream> | ||
#include <string> | ||
|
||
/// @brief Exit using the bit::exit(...) method automatically adding location information to the payload. | ||
/// @brief This is called if an assertion fails -- exits the program using the @c bit::exit(...) method. | ||
/// @note This is a macro that automatically adds the needed location information to the payload. | ||
#define bit_assertion_failed(...) bit::exit(__func__, __FILE__, __LINE__, std::format(__VA_ARGS__)) | ||
|
||
/// @def The `bit_always_assert` macro cannot be switched off with compiler flags. | ||
#define bit_always_assert(cond, ...) \ | ||
if (!(cond)) bit_assertion_failed("Statement '{}' is NOT true: {}\n", #cond, std::format(__VA_ARGS__)) | ||
|
||
// If BIT_NDEBUG is set then BIT_DEBUG should *not* be set. | ||
#if defined(BIT_NDEBUG) | ||
#undef BIT_DEBUG | ||
#endif | ||
|
||
/// @def The `bit_debug_assert` macro expands to a no-op *unless* the `BIT_DEBUG` flag is set. | ||
#ifdef BIT_DEBUG | ||
#define bit_debug_assert(cond, ...) bit_always_assert(cond, __VA_ARGS__) | ||
#else | ||
#define bit_debug_assert(cond, ...) void(0) | ||
#endif | ||
|
||
/// @def The `bit_assert`macro expands to a no-op *only if* the `BIT_NDEBUG` flag is set. | ||
#ifdef BIT_NDEBUG | ||
#define bit_assert(cond, ...) void(0) | ||
#else | ||
#define bit_assert(cond, ...) bit_always_assert(cond, __VA_ARGS__) | ||
#endif | ||
|
||
namespace bit { | ||
|
||
/// @brief Given a path like `/home/jj/dev/project/src/foo.cpp` this returns its basename `foo.cpp` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.