My Project
Public Member Functions | Static Public Member Functions | Related Functions | List of all members
bsl::source_location Class Referencefinal

This class implements the source_location specification that will eventually be included in C++20. We make some changes to the specification to support AUTOSAR, but these changes should not change how the code is compiled or used, with the exception that we do not include the column() as this does not seem to be implemented by any compilers yet. More...

#include <source_location.hpp>

Public Member Functions

constexpr source_location () noexcept
 Creates a default constructed source location. By default, a source location's file name is "unknown", the function name is "unknown" and the line location is "-1". More...
 
constexpr file_type file_name () const noexcept
 Returns the file name associated with the bsl::source_location. More...
 
constexpr func_type function_name () const noexcept
 Returns the function name associated with the bsl::source_location. More...
 
constexpr line_type line () const noexcept
 Returns the line location associated with the bsl::source_location. More...
 

Static Public Member Functions

static constexpr source_location current (file_type const current_file=BSL_BUILTIN_FILE, func_type const current_func=BSL_BUILTIN_FUNCTION, line_type const current_line=BSL_BUILTIN_LINE) noexcept
 Constructs a new source_location object corresponding to the location of the call site. More...
 

Related Functions

(Note that these are not member functions.)

template<typename T >
constexpr out< T > operator<< (out< T > const o, source_location const &sloc) noexcept
 Outputs the provided bsl::source_location to the provided output type. More...
 

Detailed Description

This class implements the source_location specification that will eventually be included in C++20. We make some changes to the specification to support AUTOSAR, but these changes should not change how the code is compiled or used, with the exception that we do not include the column() as this does not seem to be implemented by any compilers yet.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_source_location_overview() noexcept
{
}
}

Constructor & Destructor Documentation

◆ source_location()

constexpr bsl::source_location::source_location ( )
inlinenoexcept

Creates a default constructed source location. By default, a source location's file name is "unknown", the function name is "unknown" and the line location is "-1".

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_source_location_default_constructor() noexcept
{
}
}

Member Function Documentation

◆ current()

static constexpr source_location bsl::source_location::current ( file_type const  current_file = BSL_BUILTIN_FILE,
func_type const  current_func = BSL_BUILTIN_FUNCTION,
line_type const  current_line = BSL_BUILTIN_LINE 
)
inlinestaticnoexcept

Constructs a new source_location object corresponding to the location of the call site.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_source_location_current() noexcept
{
}
}
Note
You should not set the parameters manually. Instead, use the default parameters which will contain the location information provided by the compiler.
We DO NOT ensure by contract that the source location contains valid pointers for the file name and function name which means the resulting source_location could return a nullptr for both the file name and function name. Care should be taken to ensure the proper checks are made as needed.
Instead of using bsl::source_location::current() to get the current source_location, use bsl::here() which provides a function with less verbosity.
Parameters
current_filedefaults to the current file name
current_funcdefaults to the current function name
current_linedefaults to the current line location
Returns
returns a new source_location object corresponding to the location of the call site of current().

◆ file_name()

constexpr file_type bsl::source_location::file_name ( ) const
inlinenoexcept

Returns the file name associated with the bsl::source_location.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_source_location_file_name() noexcept
{
bsl::print() << "success: " << bsl::here().file_name() << bsl::endl;
}
}
Returns
returns the file name associated with the

◆ function_name()

constexpr func_type bsl::source_location::function_name ( ) const
inlinenoexcept

Returns the function name associated with the bsl::source_location.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_source_location_function_name() noexcept
{
bsl::print() << "success: " << bsl::here().function_name() << bsl::endl;
}
}
Returns
returns the function name associated with the

◆ line()

constexpr line_type bsl::source_location::line ( ) const
inlinenoexcept

Returns the line location associated with the bsl::source_location.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_source_location_line() noexcept
{
bsl::print() << "success: " << bsl::here().line() << bsl::endl;
}
}
Returns
returns the line location associated with the

Friends And Related Function Documentation

◆ operator<<()

template<typename T >
constexpr out< T > operator<< ( out< T > const  o,
source_location const &  sloc 
)
related

Outputs the provided bsl::source_location to the provided output type.

Template Parameters
Tthe type of outputter provided
Parameters
othe instance of the outputter used to output the value.
slocthe bsl::source_location to output
Returns
return o

The documentation for this class was generated from the following file: