My Project
Functions
discard.hpp File Reference

Go to the source code of this file.

Functions

template<typename... ARGS>
constexpr void bsl::discard (ARGS &&... args) noexcept
 This function discards a parameter that it is given. This is the same as executing a static cast. The reason this exists is it better documents the intent to discard the result of a function or an intentionally unused parameter. This function also exists because in some cases, we must pass the address of a discard as as a template parameter, which cannot be done with a static cast. More...
 

Detailed Description

Function Documentation

◆ discard()

template<typename... ARGS>
constexpr void bsl::discard ( ARGS &&...  args)
noexcept

This function discards a parameter that it is given. This is the same as executing a static cast. The reason this exists is it better documents the intent to discard the result of a function or an intentionally unused parameter. This function also exists because in some cases, we must pass the address of a discard as as a template parameter, which cannot be done with a static cast.

#include <bsl/discard.hpp>
#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_discard_overview() noexcept
{
bool val{};
bsl::print() << "success\n";
}
}

SUPPRESSION: PRQA 4050 - exception required

  • We suppress this because M0-1-8 states that all functions marked as returning void must have external side effects, which this function does not. AUTOSAR allows the use of static_cast<void> to mark a parameter or return as unused which is all that this is doing in a less verbose, more self-documenting way.
Template Parameters
ARGSthe types that define the provided arguments to ignore
Parameters
argsthe arguments to ignore