TRLC Platform Library  1.0.0
Header-only C++ library for compile-time platform detection and abstraction
TRLC Platform Library

Introduction

The TRLC Platform Library is a comprehensive, header-only C++ library for compile-time platform detection and abstraction. It provides zero-overhead detection of compilers, platforms, architectures, and language features, enabling developers to write portable, optimized code that adapts to different environments.

Key Features

  • Header-Only Design: No linking required, easy integration
  • Zero Runtime Overhead: All detection occurs at compile time
  • Comprehensive Detection: Covers compilers, platforms, architectures, and features
  • Modern C++: Requires C++17, supports up to C++23
  • Cross-Platform: Works on Windows, Linux, macOS, and embedded systems
  • Thread-Safe: All functions are constexpr and side-effect free

API Modules

The library is organized into several header modules:

Core Module (trlc/platform/core.hpp)

  • Main entry point and unified reporting
  • Aggregates all detection capabilities
  • Optional debug utilities integration

Architecture Detection (trlc/platform/architecture.hpp)

  • CPU architecture detection (x86, ARM, MIPS, PowerPC, RISC-V, SPARC)
  • Pointer size and endianness detection
  • SIMD and vector instruction capabilities
  • Cache line size estimation

Compiler Detection (trlc/platform/compiler.hpp)

  • Compiler identification (GCC, Clang, MSVC, Intel)
  • Version parsing and comparison
  • Compiler-specific optimization support

Platform Detection (trlc/platform/platform.hpp)

  • Operating system detection (Windows, Linux, macOS, BSD, mobile)
  • Environment type classification
  • Platform-specific feature detection

Feature Detection (trlc/platform/features.hpp)

  • Language feature detection (exceptions, RTTI, threads)
  • Runtime feature detection (SIMD instruction sets)
  • C++ standard library feature detection

C++ Standard Detection (trlc/platform/cpp_standard.hpp)

  • C++ standard version detection (C++17, C++20, C++23)
  • Standard library feature availability

Endianness Utilities (trlc/platform/endianness.hpp)

  • Byte order detection and conversion
  • Network byte order utilities
  • Efficient byte swapping functions

Utility Macros (trlc/platform/macros.hpp)

  • Portable utility macros for common operations
  • Compiler attribute abstractions
  • Optimization hints and annotations

Debug Utilities (trlc/platform/debug.hpp) [Optional]

  • Debug assertions and diagnostics
  • Performance profiling helpers
  • Memory debugging support

Basic Usage

Quick Start

// Simple architecture detection
constexpr auto arch = trlc::platform::getCpuArchitecture();
// x86_64 specific optimizations
}
// Comprehensive platform report
std::cout << report.generateReport() << std::endl;
Main entry point for TRLC platform detection and abstraction.
static CpuArchitecture getCpuArchitecture()
PlatformReport getPlatformReport()
Definition: core.hpp:337
@ x86_64
Intel/AMD x86-64 (64-bit) - Modern desktop/server processors.

Conditional Compilation

// Architecture-specific code
process_with_simd(data);
} else {
process_scalar(data);
}
// Compiler-specific optimizations
constexpr auto compiler = trlc::platform::getCompilerType();
if constexpr (compiler == trlc::platform::CompilerType::gcc) {
// GCC-specific code
} else if constexpr (compiler == trlc::platform::CompilerType::clang) {
// Clang-specific code
}
@ clang
Clang/LLVM compiler - Modern, standards-compliant.
@ gcc
GNU Compiler Collection - Cross-platform, open-source.
static bool hasSimdSupport()
static CompilerType getCompilerType()
Detects the current compiler type at compile time.
Definition: compiler.hpp:323

Performance Optimization

// Cache-line aligned data structures
constexpr auto info = trlc::platform::getArchitectureInfo();
alignas(info.cache_line_size) struct CacheAligned {
std::atomic<int> counter;
char padding[info.cache_line_size - sizeof(std::atomic<int>)];
};
// Feature-based algorithm selection
template<typename T>
void sort_array(std::vector<T>& data) {
parallel_sort(data); // Use vectorized sorting
} else if constexpr (trlc::platform::hasThreads()) {
threaded_sort(data); // Use multi-threaded sorting
} else {
std::sort(data.begin(), data.end()); // Fallback
}
}
static bool hasThreads()
Detects if threading support is available.
Definition: features.hpp:230
static ArchitectureInfo getArchitectureInfo()
static bool hasVectorInstructions()

Integration

CMake Integration

# Using FetchContent
include(FetchContent)
FetchContent_Declare(
trlc-platform
GIT_REPOSITORY https://github.com/your-org/trlc-platform.git
GIT_TAG main
)
FetchContent_MakeAvailable(trlc-platform)
target_link_libraries(your_target PRIVATE trlc::platform)

Header-Only Usage

// Simply include the headers you need
#include "trlc/platform/architecture.hpp" // For architecture detection
#include "trlc/platform/compiler.hpp" // For compiler detection
#include "trlc/platform/features.hpp" // For feature detection
// Or include everything
CPU architecture and byte order detection for trlc-platform.
Compiler detection and capability utilities.
Language and runtime feature detection utilities.

Performance Characteristics

  • Compile-Time Evaluation: All detection functions are constexpr
  • Zero Runtime Cost: No runtime overhead for platform detection
  • Optimizable: Enables dead code elimination through if constexpr
  • Header-Only: No linking overhead or binary size impact
  • Thread-Safe: All functions are pure and side-effect free

Compatibility

Compiler Support

  • GCC 7.0+ (full C++17 support)
  • Clang 5.0+ (full C++17 support)
  • MSVC 19.14+ (Visual Studio 2017 15.7+)
  • Intel C++ 19.0+

Platform Support

  • Windows (x86, x64, ARM64)
  • Linux (x86, x64, ARM, ARM64, MIPS, PowerPC, RISC-V)
  • macOS (x64, ARM64)
  • FreeBSD, OpenBSD, NetBSD
  • Android, iOS
  • Embedded systems (various architectures)

Standards Support

  • C++17 (minimum required)
  • C++20 (full support)
  • C++23 (detection and partial support)

License

This library is released under the MIT License. See LICENSE file for details.

Authors

TRLC Platform Team

Version
1.0.0
Date
2025