spy v3.0.0
Andrée Borrel
Loading...
Searching...
No Matches

The compiler processing the code, and the literals naming its versions. More...

Detailed Description

The compiler processing the code, and the literals naming its versions.

spy::compiler reports the toolchain as itself: a compiler that imitates another still answers with its own name. The literals gathered here name a version to compare it against.

Variables

constexpr compiler_type spy::compiler
 Compiler reporting value.

Functions

template<char... c>
constexpr auto spy::literal::operator""_clang ()
 User-defined suffix for Clang version definition.
template<char... c>
constexpr auto spy::literal::operator""_clangcl ()
 User-defined suffix for ClangCL version definition.
template<char... c>
constexpr auto spy::literal::operator""_dpcpp ()
 User-defined suffix for Intel DCP++/ICPX version definition.
template<char... c>
constexpr auto spy::literal::operator""_em ()
 User-defined suffix for Emscripten version definition.
template<char... c>
constexpr auto spy::literal::operator""_gcc ()
 User-defined suffix for G++ version definition.
template<char... c>
constexpr auto spy::literal::operator""_intel ()
 User-defined suffix for Intel ICC version definition.
template<char... c>
constexpr auto spy::literal::operator""_mingw32 ()
 User-defined suffix for MINGW32 version definition.
template<char... c>
constexpr auto spy::literal::operator""_mingw64 ()
 User-defined suffix for MINGW64 version definition.
template<char... c>
constexpr auto spy::literal::operator""_msvc ()
 User-defined suffix for MSVC version definition.
template<char... c>
constexpr auto spy::literal::operator""_nvcc ()
 User-defined suffix for NVCC version definition.

Variable Documentation

◆ compiler

compiler_type spy::compiler
inlineconstexpr

#include <spy/compiler.hpp>

Compiler reporting value.

The spy::compiler object can be compared to any other compiler related value to verify if the code being compiled with a specific compiler.

Any compiler related value can be checked for equality or ordering for a given version. The targeted version is then specified using a compiler-dependent literal.

Additionally, any of the compiler related value are convertible to bool. They evaluates to true if they matches the correct compiler currently used.

Supported Value

Name Compiler
spy::clang_ Clang
spy::clangcl_ Clang-CL, Clang driving the Microsoft toolchain
spy::dpcpp_ Intel DPC++/ICPX
spy::emscripten_ Emscripten
spy::gcc_ G++
spy::intel_ Intel ICC
spy::mingw32_ MINGW32
spy::mingw64_ MINGW64
spy::msvc_ Microsoft Visual Studio
spy::nvcc_ NVIDIA NVCC

Clang-CL, MINGW32 and MINGW64 each report as themselves. Under MINGW, spy::compiler == spy::gcc_ is false; under Clang-CL, spy::compiler == spy::msvc_ is false.

Example

#include <iostream>
#include <spy/spy.hpp>
int main()
{
// Comparisons
if constexpr(spy::compiler == spy::gcc_) std::cout << "This code compiled with g++.\n";
else if constexpr(spy::compiler == spy::clang_) std::cout << "This code compiled with clang.\n";
else if constexpr(spy::compiler == spy::dpcpp_) std::cout << "This code compiled with ICPX.\n";
// Direct test
if constexpr(spy::gcc_) std::cout << "This code compiled with g++.\n";
else if constexpr(spy::clang_) std::cout << "This code compiled with clang.\n";
else if constexpr(spy::dpcpp_) std::cout << "This code compiled with ICPX.\n";
// Version checks
using namespace spy::literal;
if constexpr(spy::compiler == 16'0_clang) std::cout << "This code compiled with clang 16.\n";
if constexpr(spy::compiler >= 15'0_clang)
std::cout << "This code compiled with clang 15 or ulterior.\n";
}
constexpr compiler_type compiler
Compiler reporting value.
Definition compiler.hpp:182