@@ -17,6 +17,7 @@ A simple, lightweight, header-only C++ library for universal string conversion w
1717- [ Type Detection System] ( #type-detection-system )
1818- [ API Reference] ( #api-reference )
1919- [ Building and Testing] ( #building-and-testing )
20+ - [ Running Demos] ( #running-demos )
2021- [ Performance Considerations] ( #performance-considerations )
2122- [ Contributing] ( #contributing )
2223- [ License] ( #license )
@@ -68,31 +69,37 @@ int main() {
6869 std::map<std::string, int> map = {{"key", 123}};
6970 auto s8 = ustr::to_string(map); // {"key": 123}
7071
72+ // Enum support (integer or symbolic)
73+ enum Status { PENDING, APPROVED, REJECTED };
74+ auto s9 = ustr::to_string(APPROVED); // "1" (or "APPROVED" with specialization)
75+
7176 // Custom specializations possible
7277 long long x = 123456789012345LL;
73- auto s9 = ustr::to_string(x); // Can be customized to "123456789012345LL"
78+ auto s10 = ustr::to_string(x); // Can be customized to "123456789012345LL"
7479
7580 return 0;
7681}
7782```
7883
7984**What makes USTR special:**
80- - 🎯 **One function for everything** - `ustr::to_string()` works with any type
81- - 🧠 **Intelligent detection** - Automatically finds the best conversion method
82- - ⚡ **Zero overhead** - Uses optimal conversion for each type
83- - 🔧 **Fully customizable** - Easy specialization and custom implementations
84- - 📦 **Header-only** - Just include and use, no dependencies
85+ - **One function for everything** - `ustr::to_string()` works with any type
86+ - **Intelligent detection** - Automatically finds the best conversion method
87+ - **Zero overhead** - Uses optimal conversion for each type
88+ - **Fully customizable** - Easy specialization and custom implementations
89+ - **Header-only** - Just include and use, no dependencies
8590
8691## Features
8792
88- - 🚀 **Header-only** - Just include `ustr.h` and start using
89- - 🎯 **Intelligent type detection** - Automatically selects the best conversion method
90- - ⚡ **Performance optimized** - Uses `std::to_string` for numeric types
91- - 🔧 **Highly customizable** - Easy specialization for custom types
92- - 🛡️ **Type safe** - SFINAE-based implementation prevents compilation errors
93- - 📦 **Zero dependencies** - Works with standard C++ library only
94- - 🎨 **Clean API** - Single function interface: `ustr::to_string(value)`
95- - ✅ **Well tested** - Comprehensive test suite included
93+ - **Header-only** - Just include `ustr.h` and start using
94+ - **Intelligent type detection** - Automatically selects the best conversion method
95+ - **Performance optimized** - Uses `std::to_string` for numeric types
96+ - **Highly customizable** - Easy specialization for custom types
97+ - **Type safe** - SFINAE-based implementation prevents compilation errors
98+ - **Zero dependencies** - Works with standard C++ library only
99+ - **Clean API** - Single function interface: `ustr::to_string(value)`
100+ - **Container support** - Works with vectors, maps, pairs, tuples, arrays
101+ - **Enum conversion** - Multiple approaches for enum to string conversion
102+ - **Well tested** - Comprehensive test suite included
96103
97104## Quick Start
98105
@@ -129,7 +136,7 @@ USTR is a header-only library. Simply:
129136
130137``` bash
131138# Clone the repository
132- git clone https://github.com/your-username /ustr.git
139+ git clone https://github.com/vpiotr /ustr.git
133140
134141# Include in your project
135142# include "ustr/include/ustr/ustr.h"
@@ -240,6 +247,48 @@ debugLog("is_premium", true);
240247debugLog("location", Point(40.7128, -74.0060));
241248```
242249
250+ ### Enum Conversions
251+
252+ USTR supports multiple approaches for enum to string conversion:
253+
254+ ``` cpp
255+ // Approach 1: Default integer conversion (automatic)
256+ enum Color { RED, GREEN, BLUE };
257+ auto s1 = ustr::to_string(GREEN); // "1" (shows underlying value)
258+
259+ // Approach 2: Symbolic conversion with custom specialization
260+ enum class LogLevel { DEBUG, INFO, WARNING, ERROR };
261+
262+ // Enable custom specialization
263+ namespace ustr {
264+ template<> struct has_custom_specialization<LogLevel > : std::true_type {};
265+ namespace details {
266+ template<>
267+ inline std::string to_string_impl<LogLevel >(const LogLevel& value) {
268+ switch(value) {
269+ case LogLevel::DEBUG: return "DEBUG";
270+ case LogLevel::INFO: return "INFO";
271+ case LogLevel::WARNING: return "WARNING";
272+ case LogLevel::ERROR: return "ERROR";
273+ default: return "UNKNOWN";
274+ }
275+ }
276+ }
277+ }
278+
279+ auto s2 = ustr::to_string(LogLevel::WARNING); // "WARNING" (symbolic name)
280+
281+ // Enums work in containers too
282+ std::vector<Color> colors = {RED, GREEN, BLUE};
283+ auto s3 = ustr::to_string(colors); // "[ 0, 1, 2] " or symbolic if specialized
284+
285+ std::map<LogLevel, std::string> messages = {
286+ {LogLevel::INFO, "All good"},
287+ {LogLevel::ERROR, "Failed"}
288+ };
289+ auto s4 = ustr::to_string(messages); // {INFO: "All good", ERROR: "Failed"}
290+ ```
291+
243292## Type Detection System
244293
245294USTR uses three main type traits for intelligent conversion:
@@ -389,7 +438,7 @@ Boolean constant indicating if type `T` has a custom `to_string_impl` specializa
389438
390439``` bash
391440# Quick build (Release mode with tests and demos)
392- ./cmake_build .sh
441+ ./rebuild .sh
393442
394443# Or step by step
395444mkdir build
@@ -398,22 +447,22 @@ cmake ..
398447make
399448
400449# Build options
401- ./cmake_build .sh --help # Show all options
402- ./cmake_build .sh -t Debug # Debug build
403- ./cmake_build .sh --no-tests # Skip tests
404- ./cmake_build .sh --no-demos # Skip demos
405- ./cmake_build .sh --with-docs # Build documentation (requires Doxygen)
406- ./cmake_build .sh --prefix /usr/local # Set install prefix
450+ ./rebuild .sh --help # Show all options
451+ ./rebuild .sh -t Debug # Debug build
452+ ./rebuild .sh --no-tests # Skip tests
453+ ./rebuild .sh --no-demos # Skip demos
454+ ./rebuild .sh --with-docs # Build documentation (requires Doxygen)
455+ ./rebuild .sh --prefix /usr/local # Set install prefix
407456```
408457
409458### Building with Shell Scripts (Alternative)
410459
411460``` bash
412461# Make scripts executable
413- chmod +x build .sh run_tests.sh run_demos.sh
462+ chmod +x rebuild .sh run_tests.sh run_demos.sh
414463
415464# Build everything (tests and demos)
416- ./build .sh
465+ ./rebuild .sh
417466
418467# Or build manually
419468g++ -std=c++11 -Wall -Iinclude -o build/ustr_core_features_test tests/ustr_core_features_test.cpp
@@ -435,22 +484,98 @@ cd build && ctest
435484# Or run directly
436485./build/bin/ustr_core_features_test # Core features tests (CMake build)
437486./build/bin/ustr_container_test # Container tests (CMake build)
438- ./build/ustr_core_features_test # Shell script build
439- ./build/ustr_container_test # Shell script build
440487```
441488
442489### Running Demos
443490
491+ USTR includes several comprehensive demos that showcase different aspects of the library:
492+
493+ #### Basic Demo (` ustr_demo ` )
494+ ``` bash
495+ ./build/bin/ustr_demo
496+ ```
497+ Demonstrates fundamental USTR functionality including:
498+ - Basic type conversions (numeric, boolean, character, string)
499+ - Custom classes with ` to_string() ` methods vs streamable classes
500+ - Type detection and conversion priority
501+ - Container support (vectors, maps, pairs, tuples)
502+ - Non-streamable types and fallback behavior
503+
504+ #### Comprehensive Demo (` comprehensive_demo ` )
505+ ``` bash
506+ ./build/bin/comprehensive_demo
507+ ```
508+ The most complete demonstration featuring:
509+ - ** All basic types** : integers, floats, booleans, characters, strings
510+ - ** Custom class hierarchies** : Vehicle, Engine, GPS, Car classes showing different conversion approaches
511+ - ** Complex containers** : Nested vectors, maps with mixed types, arrays, deques, lists, sets
512+ - ** Real-world scenarios** : Vehicle fleet management system with service records
513+ - ** Advanced features** : Custom formatting contexts, iterator-based conversions
514+ - ** Scoped formatting** : Temporary custom formatters for specific use cases
515+
516+ #### Enum Conversion Demo (` enum_conversion_demo ` )
517+ ``` bash
518+ ./build/bin/enum_conversion_demo
519+ ```
520+ ** Comprehensive guide to enum string conversion with three approaches:**
521+
522+ ** 1. Default Integer Conversion (Automatic)**
523+ - Works immediately with any enum, no setup required
524+ - Shows underlying integer values
525+ - Perfect for performance-critical code or internal IDs
526+ ``` cpp
527+ enum BasicColor { RED, GREEN, BLUE };
528+ // ustr::to_string(GREEN) returns "1"
529+ ```
530+
531+ **2. Manual Custom Specialization (Full Control)**
532+ - Complete control over conversion logic
533+ - More verbose but maximum flexibility
534+ - Ideal for complex formatting requirements
535+ ```cpp
536+ enum class LogLevel : int { DEBUG = 1, INFO = 2, WARNING = 3, ERROR = 4 };
537+ // Custom specialization returns "WARNING" instead of "3"
538+ ```
539+
540+ ** 3. Macro-Assisted Symbolic Conversion (Recommended)**
541+ - Easy to implement with minimal boilerplate
542+ - Human-readable symbolic names
543+ - Best balance of simplicity and readability
544+ ``` cpp
545+ enum Direction { NORTH, SOUTH, EAST, WEST };
546+ // Macro setup returns "NORTH" instead of "0"
547+ ```
548+
549+ The demo shows:
550+ - All three approaches with practical examples
551+ - Usage in containers (vectors, maps, pairs, tuples)
552+ - Mixed usage scenarios (combining different approaches)
553+ - Performance and readability trade-offs
554+ - Usage guidelines and recommendations
555+
556+ #### Multi-Module Demo (`multi_module_demo`)
557+ ```bash
558+ ./build/bin/multi_module_demo
559+ ```
560+ Demonstrates USTR usage across separate compilation units:
561+ - ** Module separation** : Shows how USTR works across different modules
562+ - ** Header-only verification** : Confirms no linking issues
563+ - ** Cross-module compatibility** : Custom types defined in one module work in another
564+ - ** Build system integration** : Example of multi-module CMake setup
565+
566+ #### Running All Demos
444567``` bash
445568# Using CMake (from build directory)
446569cd build && make run_demos
447570
448571# Using shell scripts
449572./run_demos.sh
450573
451- # Or run directly
452- ./build/bin/ustr_demo # CMake build
453- ./build/ustr_demo # Shell script build
574+ # Or run individual demos directly
575+ ./build/bin/ustr_demo # Basic functionality
576+ ./build/bin/comprehensive_demo # Complete feature showcase
577+ ./build/bin/enum_conversion_demo # Enum conversion approaches
578+ ./build/bin/multi_module_demo # Multi-module usage
454579```
455580
456581### Installing
@@ -461,7 +586,7 @@ cd build
461586make install
462587
463588# Or install to custom location
464- ./cmake_build .sh --prefix /path/to/install
589+ ./rebuild .sh --prefix /path/to/install
465590cd build
466591make install
467592```
@@ -493,20 +618,33 @@ ustr/
493618│ └── utest.h # Testing framework (included)
494619├── tests/
495620│ ├── CMakeLists.txt # CMake configuration for tests
496- │ ├── ustr_core_features_test.cpp # Core features test suite
497- │ └── ustr_container_test.cpp # Container-specific test suite
621+ │ ├── ustr_core_features_test.cpp # Core features test suite
622+ │ ├── ustr_container_test.cpp # Container-specific test suite
623+ │ ├── ustr_custom_classes_test.cpp # Custom classes test suite
624+ │ ├── ustr_enum_test.cpp # Enum conversion test suite
625+ │ ├── ustr_format_context_test.cpp # Format context test suite
626+ │ ├── ustr_pair_test.cpp # Pair conversion test suite
627+ │ ├── ustr_tuple_test.cpp # Tuple conversion test suite
628+ │ ├── ustr_custom_specialization_test.cpp # Custom specialization tests
629+ │ └── ustr_quoted_str_test.cpp # Quoted string test suite
498630├── demos/
499631│ ├── CMakeLists.txt # CMake configuration for demos
500- │ └── ustr_demo.cpp # Usage examples and demonstrations
632+ │ ├── ustr_demo.cpp # Basic usage examples and demonstrations
633+ │ ├── comprehensive_demo.cpp # Complete feature showcase with real-world scenarios
634+ │ ├── enum_conversion_demo.cpp # Enum conversion approaches (integer, symbolic, custom)
635+ │ └── multi_module/ # Multi-module demo project
636+ │ ├── main.cpp # Main demo coordinator
637+ │ ├── module1/ # First module with basic types
638+ │ └── module2/ # Second module with custom classes
501639├── docs/
502640│ ├── CMakeLists.txt # CMake configuration for documentation
503641│ └── Doxyfile.in # Doxygen configuration template
504642├── cmake/
505643│ └── ustr-config.cmake.in # CMake package configuration template
506644├── build/ # Build output directory (created by build)
507645├── CMakeLists.txt # Main CMake configuration
508- ├── cmake_build .sh # CMake build script (recommended)
509- ├── build .sh # Legacy shell build script
646+ ├── rebuild .sh # CMake build script (recommended)
647+ ├── build_docs .sh # Documentation build script
510648├── run_tests.sh # Test runner script
511649├── run_demos.sh # Demo runner script
512650└── README.md # This file
@@ -538,13 +676,20 @@ Contributions are welcome! Please follow these guidelines:
5386762 . ** Testing** : Add tests for new features in appropriate test file:
539677 - Core functionality: ` tests/ustr_core_features_test.cpp `
540678 - Container functionality: ` tests/ustr_container_test.cpp `
679+ - Custom classes: ` tests/ustr_custom_classes_test.cpp `
680+ - Enum support: ` tests/ustr_enum_test.cpp `
681+ - Format context: ` tests/ustr_format_context_test.cpp `
682+ - Pair support: ` tests/ustr_pair_test.cpp `
683+ - Tuple support: ` tests/ustr_tuple_test.cpp `
684+ - Custom specializations: ` tests/ustr_custom_specialization_test.cpp `
685+ - Quoted strings: ` tests/ustr_quoted_str_test.cpp `
5416863 . ** Documentation** : Update README and inline documentation
5426874 . ** Compatibility** : Maintain C++11 compatibility
543688
544689### Running Tests Before Contributing
545690
546691``` bash
547- ./build .sh && ./run_tests.sh
692+ ./rebuild .sh && ./run_tests.sh
548693```
549694
550695### Adding New Features
@@ -553,7 +698,18 @@ Contributions are welcome! Please follow these guidelines:
5536982 . Add tests to appropriate test file:
554699 - Core functionality: ` tests/ustr_core_features_test.cpp `
555700 - Container functionality: ` tests/ustr_container_test.cpp `
556- 3 . Add examples to ` demos/ustr_demo.cpp ` if applicable
701+ - Custom classes: ` tests/ustr_custom_classes_test.cpp `
702+ - Enum support: ` tests/ustr_enum_test.cpp `
703+ - Format context: ` tests/ustr_format_context_test.cpp `
704+ - Pair support: ` tests/ustr_pair_test.cpp `
705+ - Tuple support: ` tests/ustr_tuple_test.cpp `
706+ - Custom specializations: ` tests/ustr_custom_specialization_test.cpp `
707+ - Quoted strings: ` tests/ustr_quoted_str_test.cpp `
708+ 3 . ** Examples** : Add examples to appropriate demo files if applicable:
709+ - Basic examples: ` demos/ustr_demo.cpp `
710+ - Complex scenarios: ` demos/comprehensive_demo.cpp `
711+ - Enum features: ` demos/enum_conversion_demo.cpp `
712+ - Multi-module usage: ` demos/multi_module/ `
5577134 . Update README.md
558714
559715## License
0 commit comments