Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import C assert in cpp20 experimental

I'd like to use the C assert with C++20 in Visual Studio 2019 (compiling with std:c++latest), but I couldn't find the correct module to import. Is it already supported and if yes, which module I should import?

import std.core;
constexpr auto f()
{
    return "Hello world!";
}
int main()
{
    static_assert(f() == "Hello world!"); // Compile time assert works.
    //assert(f() == "Hello world!"); // How to import runtime assert()?
    //[[assert: f() == "Hello world!"]] // Contracts were removed from cpp20.
    std::cout << f();
}

Output: Hello world!

like image 830
Roi Danton Avatar asked Aug 10 '26 20:08

Roi Danton


1 Answers

Modules do not contain macros. Importing legacy module headers will bring in macros, but import std.core; or whatever never will bring in a macro.

like image 93
Nicol Bolas Avatar answered Aug 13 '26 10:08

Nicol Bolas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!