tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
source_location Struct Reference

A class representing information about the source code, such as file names, line numbers, and function names. More...

#include <source_location.hpp>

Public Member Functions

constexpr source_location () noexcept=default
 
constexpr auto column () const noexcept -> etl::uint_least32_t
 
constexpr auto file_name () const noexcept -> char const *
 
constexpr auto function_name () const noexcept -> char const *
 
constexpr auto line () const noexcept -> etl::uint_least32_t
 

Static Public Member Functions

static consteval auto current (uint_least32_t const line=TETL_BUILTIN_LINE(), uint_least32_t const column=TETL_BUILTIN_COLUMN(), char const *const file=TETL_BUILTIN_FILE(), char const *const function=TETL_BUILTIN_FUNCTION()) noexcept -> source_location
 

Detailed Description

A class representing information about the source code, such as file names, line numbers, and function names.

// SPDX-License-Identifier: BSL-1.0
#include <stdio.h>
#if defined(__cpp_consteval)
static auto log(etl::string_view const message, etl::source_location const location = etl::source_location::current())
-> void
{
::printf( //
"file: %s(%u:%u) `%s`: %s\n", //
location.file_name(), //
static_cast<unsigned>(location.line()), //
static_cast<unsigned>(location.column()), //
location.function_name(), //
message.data() //
);
}
template <typename T>
static auto fun(T x) -> void
{
log(x);
}
auto main(int /*argc*/, char const** /*argv*/) -> int
{
log("Hello world!");
fun("Hello C++20!");
return 0;
}
#else
auto main() -> int { return 0; }
#endif
constexpr auto log(float v) noexcept -> float
Computes the natural (base e) logarithm of arg.
Definition log.hpp:44
basic_string_view< char, etl::char_traits< char > > string_view
Typedef for common character type char
Definition basic_string_view.hpp:704
constexpr auto data() const noexcept -> const_pointer
Returns a pointer to the underlying character array. The pointer is such that the range [data(); data...
Definition basic_string_view.hpp:171
A class representing information about the source code, such as file names, line numbers,...
Definition source_location.hpp:21
static consteval auto current(uint_least32_t const line=TETL_BUILTIN_LINE(), uint_least32_t const column=TETL_BUILTIN_COLUMN(), char const *const file=TETL_BUILTIN_FILE(), char const *const function=TETL_BUILTIN_FUNCTION()) noexcept -> source_location
Definition source_location.hpp:22
Examples
source_location.cpp.

Constructor & Destructor Documentation

◆ source_location()

source_location ( )
constexprdefaultnoexcept

Member Function Documentation

◆ column()

auto column ( ) const -> etl::uint_least32_t
inlinenodiscardconstexprnoexcept

◆ current()

consteval auto current ( uint_least32_t const line = TETL_BUILTIN_LINE(),
uint_least32_t const column = TETL_BUILTIN_COLUMN(),
char const *const file = TETL_BUILTIN_FILE(),
char const *const function = TETL_BUILTIN_FUNCTION() ) -> source_location
inlinestaticnodiscardconstevalnoexcept

◆ file_name()

auto file_name ( ) const -> char const*
inlinenodiscardconstexprnoexcept

◆ function_name()

auto function_name ( ) const -> char const*
inlinenodiscardconstexprnoexcept

◆ line()

auto line ( ) const -> etl::uint_least32_t
inlinenodiscardconstexprnoexcept

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