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
}
std::cout << report.generateReport() << std::endl;
Main entry point for TRLC platform detection and abstraction.
Conditional Compilation
process_with_simd(data);
} else {
process_scalar(data);
}
}
Performance Optimization
alignas(info.cache_line_size) struct CacheAligned {
std::atomic<int> counter;
char padding[info.cache_line_size - sizeof(std::atomic<int>)];
};
template<typename T>
void sort_array(std::vector<T>& data) {
parallel_sort(data);
threaded_sort(data);
} else {
std::sort(data.begin(), data.end());
}
}
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
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