gtopt/as_label.hpp file

String label generation utilities.

This module provides compile-time string label generation functionality with:

  • Efficient concatenation of multiple values
  • Type-safe string conversion
  • Custom separator support
  • Move semantics optimization

The main interface is the as_label() function which:

  • Accepts any number of arguments of different types
  • Converts each argument to string representation
  • Joins them with a configurable separator
  • Returns a concatenated std::string (case is preserved)

Use lowercase(str) to produce a lazy zero-copy view that applies per-character lowercasing. Pass the result directly to as_label() to write lowercased text into the output without an intermediate allocation:

std::string_view cn = "Generator";
auto a = as_label(lowercase(cn), 1, 2); // "generator_1_2"

Supported argument types:

  • std::string and string views
  • Built-in numeric types (converted via std::format)
  • Any type convertible to string_view
  • Any type formattable via std::format
  • Any char range (e.g. LowercaseView from lowercase())

Example usage:

auto label1 = as_label("prefix", 42, "suffix"); // "prefix_42_suffix"
auto label2 = as_label<'-'>("a", "b", "c");    // "a-b-c"
auto label3 = as_label(lowercase("Class"), 42); // "class_42"

Namespaces

namespace gtopt
namespace gtopt::detail

Classes

struct gtopt::detail::IntCacheData
class gtopt::LowercaseView::iterator
class gtopt::SnakeCaseView::iterator
struct gtopt::detail::label_size
class gtopt::LowercaseView
Lazy, zero-copy view that lowercases each character on access.
class gtopt::SnakeCaseView
Lazy, zero-copy view that yields the snake_case form of a string.
class gtopt::detail::string_holder