### BOOST_CURRENT_LOCATION for Source Location Source: https://www.boost.org/doc/libs/latest/libs/assert/doc/html/assert Details the BOOST_CURRENT_LOCATION macro from , which creates a source_location object. This object captures file, line, and function information, similar to C++20's std::source_location. The example shows its use as a default function argument to easily pass caller location information to functions, useful for exception handling. ```c++ #include #include void f( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) { std::cout << "f() called from: " << loc << std::endl; } int main() { f(); } ``` ```c++ #include #include #include BOOST_NORETURN BOOST_NOINLINE void throw_invalid_argument( char const* message, boost::source_location const& loc = BOOST_CURRENT_LOCATION ) { boost::throw_exception( std::invalid_argument( message ), loc ); } T& my_class::at( size_t i ) { if( i >= size() ) throw_invalid_argument( "index out of range" ); return data()[ i ]; } ``` -------------------------------- ### Boost.Assert source_location Constructors and Methods Source: https://www.boost.org/doc/libs/latest/libs/assert/index Details the constructors for `boost::source_location`, including the default constructor, a constructor taking file, line, and function information, and a copy constructor from `std::source_location`. It also describes the `to_string` method. ```cpp constexpr source_location() noexcept; // Effects: Constructs a `source_location` object for which `file_name()` and `function_name()` return `""`, and `line()` and `column()` return `0`. ``` ```cpp constexpr source_location( char const* file, uint_least32_t line, char const* function, uint_least32_t column = 0 ) noexcept; // Effects: Constructs a `source_location` object for which `file_name()` returns `file`, `function_name()` returns `function`, `line()` returns the `line` argument and `column()` returns the `column` argument. ``` ```cpp constexpr source_location( std::source_location const& loc ) noexcept; // Effects: Constructs a `source_location` object for which `file_name()` returns `loc.file_name()`, `function_name()` returns `loc.function_name()`, `line()` returns `loc.line()` and `column()` returns `loc.column()`. ``` ```cpp std::string to_string() const; // Returns: a string representation of `*this`. ``` -------------------------------- ### source_location Constructors Source: https://www.boost.org/doc/libs/latest/libs/assert/doc/html/assert Provides the definitions for the constructors of the boost::source_location class. These constructors allow for default initialization, initialization with specific file, line, function, and column details, and copying from a std::source_location object. ```cpp constexpr source_location() noexcept; constexpr source_location( char const* file, uint_least32_t line, char const* function, uint_least32_t column = 0 ) noexcept; constexpr source_location( std::source_location const& loc ) noexcept; ``` -------------------------------- ### Boost source_location in C++ Source: https://www.boost.org/doc/libs/latest/libs/assert/index Illustrates the usage of BOOST_CURRENT_LOCATION to create a source_location object, providing file, line, and function information. This is demonstrated in a function's default argument and in a helper function for throwing exceptions with caller context. ```c++ #include #include void f( boost::source_location const& loc = BOOST_CURRENT_LOCATION ) { std::cout << "f() called from: " << loc << std::endl; } int main() { f(); } ``` ```c++ #include #include #include BOOST_NORETURN BOOST_NOINLINE void throw_invalid_argument( char const* message, boost::source_location const& loc = BOOST_CURRENT_LOCATION ) { boost::throw_exception( std::invalid_argument( message ), loc ); } T& my_class::at( size_t i ) { if( i >= size() ) throw_invalid_argument( "index out of range" ); return data()[ i ]; } ``` -------------------------------- ### source_location Member Functions Source: https://www.boost.org/doc/libs/latest/libs/assert/doc/html/assert Details the member functions of the boost::source_location class for retrieving source code location information: file name, function name, line number, and column number. It also includes the to_string method for string representation. ```cpp constexpr char const* file_name() const noexcept; constexpr char const* function_name() const noexcept; constexpr uint_least32_t line() const noexcept; constexpr uint_least32_t column() const noexcept; std::string to_string() const; ``` -------------------------------- ### Define BOOST_ASSERT macro with custom handler expansion Source: https://www.boost.org/doc/libs/latest/libs/assert/doc/html/assert Shows the expanded form of BOOST_ASSERT when BOOST_ENABLE_ASSERT_HANDLER is defined. This expansion evaluates the expression and calls a custom assertion_failed handler if the expression is false, including function name, file, and line information. ```cpp (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed(#expr, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) ``` -------------------------------- ### Boost.Assert source_location Class Definition Source: https://www.boost.org/doc/libs/latest/libs/assert/index Defines the `boost::source_location` struct, which captures source code location information such as file name, line number, function name, and column number. It includes constructors, member functions to retrieve location details, and an output stream operator. ```cpp namespace boost { struct source_location { constexpr source_location() noexcept; constexpr source_location( char const* file, uint_least32_t line, char const* function, uint_least32_t column = 0 ) noexcept; constexpr source_location( std::source_location const& loc ) noexcept; constexpr char const* file_name() const noexcept; constexpr char const* function_name() const noexcept; constexpr uint_least32_t line() const noexcept; constexpr uint_least32_t column() const noexcept; std::string to_string() const; }; template std::basic_ostream & operator<<( std::basic_ostream & os, source_location const & loc ); } // namespace boost #define BOOST_CURRENT_LOCATION /* see below */ ``` -------------------------------- ### source_location Stream Insertion Operator Source: https://www.boost.org/doc/libs/latest/libs/assert/doc/html/assert Overloads the stream insertion operator (<<) for boost::source_location objects, enabling them to be directly written to output streams. The output is generated by calling the to_string() method. ```cpp template std::basic_ostream & operator<<( std::basic_ostream & os, source_location const & loc ); ``` -------------------------------- ### BOOST_VERIFY_MSG Macro Behavior Source: https://www.boost.org/doc/libs/latest/libs/assert/doc/html/assert Explains the conditional expansion of the BOOST_VERIFY_MSG macro based on predefined macros like BOOST_DISABLE_ASSERTS, BOOST_ENABLE_ASSERT_HANDLER, and NDEBUG. It highlights how the macro behaves differently in debug and release builds, and when assertion handling is enabled or disabled. ```c++ #include // Example usage (behavior depends on compile-time defines) // BOOST_VERIFY_MSG(expression, "Error message"); ``` -------------------------------- ### Boost.Assert source_location Class Definition Source: https://www.boost.org/doc/libs/latest/libs/assert/doc/html/assert Defines the boost::source_location class, including its constructors and member functions for accessing source code location details. It also declares the stream insertion operator overload. ```cpp namespace boost { struct source_location { constexpr source_location() noexcept; constexpr source_location( char const* file, uint_least32_t line, char const* function, uint_least32_t column = 0 ) noexcept; constexpr source_location( std::source_location const& loc ) noexcept; constexpr char const* file_name() const noexcept; constexpr char const* function_name() const noexcept; constexpr uint_least32_t line() const noexcept; constexpr uint_least32_t column() const noexcept; std::string to_string() const; }; template std::basic_ostream & operator<<( std::basic_ostream & os, source_location const & loc ); } // namespace boost ``` -------------------------------- ### BOOST_VERIFY_MSG Behavior Source: https://www.boost.org/doc/libs/latest/libs/assert/index Explains the conditional expansion of the BOOST_VERIFY_MSG macro based on predefined macros like BOOST_DISABLE_ASSERTS, BOOST_ENABLE_ASSERT_HANDLER, and NDEBUG. It details how the macro behaves in different compilation environments. ```c++ #include // Example usage illustrating the concept (actual expansion is conditional) // BOOST_VERIFY_MSG(expression, "error message"); ``` -------------------------------- ### BOOST_ASSERT Macro Behavior in C++ Source: https://www.boost.org/doc/libs/latest/libs/assert/index Defines the `BOOST_ASSERT` macro, which functions like the standard `assert`. It can be configured to expand to `assert(expr)`, `((void)0)` (when `BOOST_DISABLE_ASSERTS` is defined), or call `::boost::assertion_failed` with detailed information when the expression is false (when `BOOST_ENABLE_ASSERT_HANDLER` is defined). It also handles custom debug assertions with `BOOST_ENABLE_ASSERT_DEBUG_HANDLER`. ```cpp #include void example_function(int value) { BOOST_ASSERT(value > 0); } // Example with BOOST_DISABLE_ASSERTS // #define BOOST_DISABLE_ASSERTS // #include // Example with BOOST_ENABLE_ASSERT_HANDLER // #define BOOST_ENABLE_ASSERT_HANDLER // #include // namespace boost { // void assertion_failed(char const * expr, char const * function, char const * file, long line) { // // Custom assertion failure handler // } // } ``` -------------------------------- ### Boost.Assert source_location Output Stream Operator Source: https://www.boost.org/doc/libs/latest/libs/assert/index Overloads the output stream operator `<<` for `boost::source_location`. This allows `source_location` objects to be directly inserted into output streams, typically outputting their string representation. ```cpp template std::basic_ostream & operator<<( std::basic_ostream & os, source_location const & loc ); // Effects: `os << loc.to_string()`. // Returns: `os`. ``` -------------------------------- ### Boost.Assert BOOST_CURRENT_LOCATION Macro Definition Source: https://www.boost.org/doc/libs/latest/libs/assert/index Defines the `BOOST_CURRENT_LOCATION` macro, which provides the current source code location. It has two forms: one that produces an empty location when `BOOST_DISABLE_CURRENT_LOCATION` is defined (for security), and another that uses `std::source_location::current()` for approximate equivalent behavior. ```cpp #define BOOST_CURRENT_LOCATION ::boost::source_location() // When `BOOST_DISABLE_CURRENT_LOCATION` is defined, the definition of `BOOST_CURRENT_LOCATION` is: // This allows producing executables that contain no identifying information, for security reasons. ``` ```cpp #define BOOST_CURRENT_LOCATION \ ::boost::source_location(::std::source_location::current()) // Otherwise, `BOOST_CURRENT_LOCATION` is defined as the approximate equivalent of ``` -------------------------------- ### BOOST_CURRENT_LOCATION Macro Definitions Source: https://www.boost.org/doc/libs/latest/libs/assert/doc/html/assert Defines the BOOST_CURRENT_LOCATION macro, which is used to obtain a boost::source_location object. The definition varies based on whether BOOST_DISABLE_CURRENT_LOCATION is defined, offering a security-focused option or a standard-compliant option. ```cpp #define BOOST_CURRENT_LOCATION ::boost::source_location() #define BOOST_CURRENT_LOCATION \ ::boost::source_location(::std::source_location::current()) ``` -------------------------------- ### Declare boost::assertion_failed_msg handler function with message Source: https://www.boost.org/doc/libs/latest/libs/assert/doc/html/assert Declares the assertion_failed_msg function in the boost namespace that users must define to handle assertion failures with custom messages. Includes the failed expression string, custom message, function name, file path, and line number. ```cpp namespace boost { #if defined(BOOST_ASSERT_HANDLER_IS_NORETURN) BOOST_NORETURN #endif void assertion_failed_msg(char const * expr, char const * msg, char const * function, char const * file, long line); } ``` -------------------------------- ### BOOST_ASSERT_IS_VOID Macro Usage Source: https://www.boost.org/doc/libs/latest/libs/assert/doc/html/assert Demonstrates the use of BOOST_ASSERT_IS_VOID to control the compilation and execution of assertion-related code. The provided C++ snippet shows a common pattern where assertion checks are conditionally compiled out when BOOST_ASSERT_IS_VOID is defined, typically in release builds to optimize performance. ```c++ void MyContainer::erase(iterator i) { // Some sanity checks, data must be ordered #ifndef BOOST_ASSERT_IS_VOID if(i != c.begin()) { iterator prev = i; --prev; BOOST_ASSERT(*prev < *i); } else if(i != c.end()) { iterator next = i; ++next; BOOST_ASSERT(*i < *next); } #endif this->erase_impl(i); } ``` -------------------------------- ### BOOST_CURRENT_FUNCTION Macro Source: https://www.boost.org/doc/libs/latest/libs/assert/doc/html/assert Describes the BOOST_CURRENT_FUNCTION macro from , which provides the name of the current enclosing function, similar to C99's __func__. It explains how it expands to a string literal or a local character array and how it defaults to "(unknown)" on compilers that do not support this feature or when BOOST_DISABLE_CURRENT_FUNCTION is defined for security reasons. ```c++ #include // Example usage: // const char* current_func = BOOST_CURRENT_FUNCTION; // std::cout << "Currently in: " << current_func << std::endl; ``` -------------------------------- ### BOOST_ASSERT_MSG Macro Behavior in C++ Source: https://www.boost.org/doc/libs/latest/libs/assert/index Provides `BOOST_ASSERT_MSG`, an extension of `BOOST_ASSERT` that accepts an additional message argument. Similar to `BOOST_ASSERT`, its behavior can be controlled by `BOOST_DISABLE_ASSERTS` and `BOOST_ENABLE_ASSERT_HANDLER`, which might call `::boost::assertion_failed_msg` upon failure. It also supports `BOOST_ENABLE_ASSERT_DEBUG_HANDLER` for debug builds. ```cpp #include void example_function_with_msg(int value, const char* message) { BOOST_ASSERT_MSG(value > 0, message); } // Example with BOOST_ENABLE_ASSERT_HANDLER and custom handler // #define BOOST_ENABLE_ASSERT_HANDLER // #include // namespace boost { // void assertion_failed_msg(char const * expr, char const * msg, char const * function, char const * file, long line) { // // Custom assertion failure handler with message // } // } ``` -------------------------------- ### Define BOOST_ASSERT_MSG macro with custom message handler expansion Source: https://www.boost.org/doc/libs/latest/libs/assert/doc/html/assert Shows the expanded form of BOOST_ASSERT_MSG when BOOST_ENABLE_ASSERT_HANDLER is defined. This expansion evaluates the expression and calls assertion_failed_msg with an additional custom error message parameter if the expression is false. ```cpp (BOOST_LIKELY(!!(expr))? ((void)0): ::boost::assertion_failed_msg(#expr, msg, BOOST_CURRENT_FUNCTION, __FILE__, __LINE__)) ``` -------------------------------- ### Declare boost::assertion_failed handler function Source: https://www.boost.org/doc/libs/latest/libs/assert/doc/html/assert Declares the assertion_failed function in the boost namespace that users must define to handle assertion failures. The function receives the failed expression as a string, the function name, file path, and line number where the assertion occurred. ```cpp namespace boost { #if defined(BOOST_ASSERT_HANDLER_IS_NORETURN) BOOST_NORETURN #endif void assertion_failed(char const * expr, char const * function, char const * file, long line); } ``` -------------------------------- ### BOOST_CURRENT_FUNCTION Macro in C++ Source: https://www.boost.org/doc/libs/latest/libs/assert/index Details the BOOST_CURRENT_FUNCTION macro, which provides the name of the current enclosing function, similar to C99's __func__. It explains its behavior when compilers don't support this feature or when BOOST_DISABLE_CURRENT_FUNCTION is defined, resulting in 'unknown'. ```c++ #include void example_function() { // BOOST_CURRENT_FUNCTION expands to the name of example_function // For example: "void example_function()" or "example_function" // If disabled or unsupported, it expands to "(unknown)" // const char* func_name = BOOST_CURRENT_FUNCTION; } ``` -------------------------------- ### BOOST_ASSERT_IS_VOID Usage in C++ Source: https://www.boost.org/doc/libs/latest/libs/assert/index Demonstrates the use of BOOST_ASSERT_IS_VOID to conditionally compile assertion code. When defined, it prevents the execution of sanity checks, useful for optimizing release builds or when assertions are disabled. The code snippet shows a typical scenario within a container's erase method. ```c++ void MyContainer::erase(iterator i) { // Some sanity checks, data must be ordered #ifndef BOOST_ASSERT_IS_VOID if(i != c.begin()) { iterator prev = i; --prev; BOOST_ASSERT(*prev < *i); } else if(i != c.end()) { iterator next = i; ++next; BOOST_ASSERT(*i < *next); } #endif this->erase_impl(i); } ``` -------------------------------- ### BOOST_VERIFY Macro Behavior in C++ Source: https://www.boost.org/doc/libs/latest/libs/assert/index Introduces `BOOST_VERIFY`, which guarantees the evaluation of its expression, unlike `BOOST_ASSERT` which might be disabled. It behaves like `BOOST_ASSERT` when `BOOST_ENABLE_ASSERT_HANDLER` is defined, but always evaluates the expression, even when `NDEBUG` is defined. If `BOOST_DISABLE_ASSERTS` is defined, it simply evaluates the expression. ```cpp #include int potentially_side_effecting_function(int x) { // ... computation ... return x; } void verify_example(int value) { BOOST_VERIFY(potentially_side_effecting_function(value) > 0); } // Example with BOOST_DISABLE_ASSERTS // #define BOOST_DISABLE_ASSERTS // #include // void verify_example_disabled(int value) { // BOOST_VERIFY(potentially_side_effecting_function(value) > 0); // Expression is always evaluated // } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.