Funktionen können KonsequPRPR Ergebnisse liefern, auch wenn ihre Argumente nicht konstant sind, wenn sie nicht genutzt werden. Dies ist zum Beispiel std :: integral_constant :: operator t :
#include
struct A {explicit constexpr operator bool() const {return true;}};
struct B {int x = 1; explicit constexpr operator bool() const {return x;}};
template
concept C = requires(T t){std::bool_constant{};};
static_assert(C);
static_assert(!C);
< /code>
Aber das gibt mir: < /p>
:7:46: error: constraint variable 't' cannot be used in an evaluated context
7 | concept C = requires(T t){std::bool_constant};
| ^
[code]constexpr[/code] Funktionen können KonsequPRPR Ergebnisse liefern, auch wenn ihre Argumente nicht konstant sind, wenn sie nicht genutzt werden. Dies ist zum Beispiel std :: integral_constant :: operator t : [code]#include
std::integral_constant a; constexpr int b = a; // Compiles! [/code] Wie kann ich ein Konzept erstellen, um diese Eigenschaft einer Funktion zu testen? rennen auf gcc.godbolt.org [code]#include
struct A {explicit constexpr operator bool() const {return true;}}; struct B {int x = 1; explicit constexpr operator bool() const {return x;}};
template concept C = requires(T t){std::bool_constant{};};
static_assert(C); static_assert(!C); < /code> Aber das gibt mir: < /p> :7:46: error: constraint variable 't' cannot be used in an evaluated context 7 | concept C = requires(T t){std::bool_constant}; | ^ [/code]
Ich habe eine constexpr-Funktion, die CRC zur Kompilierzeit berechnet. Ich muss eine Zuordnung zwischen CRCs, die von dieser Funktion generiert werden, und String-Eingaben erstellen und sie zur...
Zum Beispiel habe ich diese Klasse:
template
class TLVParser {
public:
TLVParser(T value)
: value_(std::move(value)) {
}
void parse(const std::span& buffer, size_t& offset) {
if constexpr...
// class definition - to simulate and create a Dice class and execute its methods
class Dice
{
// properties
int dotCount = 1; // initializing the dice to show side with 1 dot for testing