TRLC Platform Library  1.0.0
Header-only C++ library for compile-time platform detection and abstraction
compiler.hpp File Reference

Compiler detection and capability utilities. More...

Go to the source code of this file.

Classes

struct  trlc::platform::CompilerVersion
 
struct  trlc::platform::CompilerInfo
 Consolidated compiler information structure. More...
 

Namespaces

 trlc
 
 trlc::platform
 

Macros

#define TRLC_COMPILER_GCC   0
 Check if current compiler is GCC (preprocessor-compatible) More...
 
#define TRLC_COMPILER_CLANG   0
 Check if current compiler is Clang (preprocessor-compatible) More...
 
#define TRLC_COMPILER_MSVC   0
 Check if current compiler is MSVC (preprocessor-compatible) More...
 
#define TRLC_COMPILER_INTEL   0
 Check if current compiler is Intel Classic (preprocessor-compatible) More...
 
#define TRLC_COMPILER_INTEL_LLVM   0
 Check if current compiler is Intel LLVM-based (preprocessor-compatible) More...
 
#define TRLC_COMPILER_MINGW   0
 Check if current compiler is MinGW (preprocessor-compatible) More...
 
#define TRLC_COMPILER_VERSION_MAJOR   0
 Get compiler version components as preprocessor macros. More...
 
#define TRLC_COMPILER_VERSION_MINOR   0
 
#define TRLC_COMPILER_VERSION_PATCH   0
 
#define TRLC_COMPILER_VERSION_ATLEAST(major, minor, patch)
 Check if compiler version is at least the specified version (preprocessor-compatible) More...
 
#define TRLC_COMPILER_VERSION   (trlc::platform::getCompilerVersion())
 Get current compiler version as a CompilerVersion object (constexpr function) More...
 
#define TRLC_COMPILER_NAME   (trlc::platform::getCompilerName())
 Get current compiler name as a string (constexpr function) More...
 

Enumerations

enum class  trlc::platform::CompilerType : int {
  trlc::platform::unknown = 0 , trlc::platform::gcc , trlc::platform::clang , trlc::platform::msvc ,
  trlc::platform::intel_classic , trlc::platform::intel_llvm , trlc::platform::mingw
}
 Compiler identification enumeration. More...
 

Functions

static CompilerType trlc::platform::getCompilerType ()
 Detects the current compiler type at compile time. More...
 
static CompilerVersion trlc::platform::getCompilerVersion ()
 Gets the compiler version at compile time. More...
 
static const char * trlc::platform::getCompilerName ()
 Gets the compiler name as a string. More...
 
static bool trlc::platform::hasBuiltinAttribute ([[maybe_unused]] const char *attribute_name)
 Checks if compiler supports __builtin attributes. More...
 
static bool trlc::platform::supportsInlineAssembly ()
 Checks if compiler supports inline assembly. More...
 
static bool trlc::platform::hasColorDiagnostics ()
 Checks if compiler supports colored diagnostics. More...
 
static CompilerInfo trlc::platform::getCompilerInfo ()
 Get consolidated compiler information. More...
 

Detailed Description

Compiler detection and capability utilities.

This header provides comprehensive compile-time compiler detection, version parsing, and capability checking for cross-platform C++ development. It enables code to adapt to different compiler capabilities and optimize for specific compiler features.

Features

  • Compiler Identification: Detect GCC, Clang, MSVC, Intel compilers
  • Version Detection: Parse major.minor.patch version numbers
  • Capability Checking: Test for specific compiler features and optimizations
  • Optimization Hints: Compiler-specific optimization directives
  • Warning Control: Compiler-specific warning management
  • Standard Compliance: C++ standard support detection

Supported Compilers

  • GCC: GNU Compiler Collection (all versions)
  • Clang: LLVM Clang compiler (all versions)
  • MSVC: Microsoft Visual C++ (VS2015+)
  • Intel Classic: Legacy Intel C++ Compiler
  • Intel LLVM: New Intel C++ Compiler based on LLVM
  • MinGW: MinGW-w64 and legacy MinGW

Performance Characteristics

  • Zero Runtime Overhead: All detection occurs at compile time
  • Header-Only: No linking required
  • Optimizable: Enables compiler-specific optimizations
  • Thread-Safe: Purely compile-time evaluation

Thread Safety

All functions in this header are thread-safe as they perform only compile-time evaluation and access no mutable state.

Definition in file compiler.hpp.

Macro Definition Documentation

◆ TRLC_COMPILER_CLANG

#define TRLC_COMPILER_CLANG   0

Check if current compiler is Clang (preprocessor-compatible)

Definition at line 560 of file compiler.hpp.

◆ TRLC_COMPILER_GCC

#define TRLC_COMPILER_GCC   0

Check if current compiler is GCC (preprocessor-compatible)

Definition at line 545 of file compiler.hpp.

◆ TRLC_COMPILER_INTEL

#define TRLC_COMPILER_INTEL   0

Check if current compiler is Intel Classic (preprocessor-compatible)

Definition at line 578 of file compiler.hpp.

◆ TRLC_COMPILER_INTEL_LLVM

#define TRLC_COMPILER_INTEL_LLVM   0

Check if current compiler is Intel LLVM-based (preprocessor-compatible)

Definition at line 587 of file compiler.hpp.

◆ TRLC_COMPILER_MINGW

#define TRLC_COMPILER_MINGW   0

Check if current compiler is MinGW (preprocessor-compatible)

Definition at line 596 of file compiler.hpp.

◆ TRLC_COMPILER_MSVC

#define TRLC_COMPILER_MSVC   0

Check if current compiler is MSVC (preprocessor-compatible)

Definition at line 569 of file compiler.hpp.

◆ TRLC_COMPILER_NAME

#define TRLC_COMPILER_NAME   (trlc::platform::getCompilerName())

Get current compiler name as a string (constexpr function)

Definition at line 670 of file compiler.hpp.

◆ TRLC_COMPILER_VERSION

#define TRLC_COMPILER_VERSION   (trlc::platform::getCompilerVersion())

Get current compiler version as a CompilerVersion object (constexpr function)

Definition at line 665 of file compiler.hpp.

◆ TRLC_COMPILER_VERSION_ATLEAST

#define TRLC_COMPILER_VERSION_ATLEAST (   major,
  minor,
  patch 
)
Value:
((TRLC_COMPILER_VERSION_MAJOR > (major)) || \
#define TRLC_COMPILER_VERSION_PATCH
Definition: compiler.hpp:647
#define TRLC_COMPILER_VERSION_MINOR
Definition: compiler.hpp:646
#define TRLC_COMPILER_VERSION_MAJOR
Get compiler version components as preprocessor macros.
Definition: compiler.hpp:645

Check if compiler version is at least the specified version (preprocessor-compatible)

Parameters
majorMinimum major version
minorMinimum minor version
patchMinimum patch version

Definition at line 656 of file compiler.hpp.

◆ TRLC_COMPILER_VERSION_MAJOR

#define TRLC_COMPILER_VERSION_MAJOR   0

Get compiler version components as preprocessor macros.

Definition at line 645 of file compiler.hpp.

◆ TRLC_COMPILER_VERSION_MINOR

#define TRLC_COMPILER_VERSION_MINOR   0

Definition at line 646 of file compiler.hpp.

◆ TRLC_COMPILER_VERSION_PATCH

#define TRLC_COMPILER_VERSION_PATCH   0

Definition at line 647 of file compiler.hpp.