TEC
A lightweight C++ library enabling safe, efficient execution in multithreaded and concurrent systems.
Loading...
Searching...
No Matches
tec_print.hpp File Reference

Provides variadic print and format utilities for the tec namespace. Implemented for compatibility with pre-C++20 compilers. More...

#include <iostream>
#include <ostream>
#include <sstream>
#include <string>
#include "tec/tec_def.hpp"

Go to the source code of this file.

Functions

Print and Format Functions

Utility functions for formatted output and string creation.

These functions provide flexible printing to output streams and string formatting with support for variadic arguments and placeholder-based formatting using "{}" syntax.

template<typename T >
void tec::print (std::ostream *out, const T &arg)
 Outputs a single argument to the specified stream.
 
template<typename T , typename... Targs>
void tec::print (std::ostream *out, const char *fmt, const T &value, Targs &&... Args)
 Outputs variadic arguments to the specified stream with formatting.
 
template<typename T >
void tec::println (std::ostream *out, const T &arg)
 Outputs a single argument to the specified stream with a newline.
 
template<typename T , typename... Targs>
void tec::println (std::ostream *out, const char *fmt, const T &value, Targs &&... Args)
 Outputs variadic arguments to the specified stream with formatting and a newline.
 
template<typename T >
void tec::print (const T &arg)
 Outputs a single argument to std::cout.
 
template<typename T , typename... Targs>
void tec::print (const char *fmt, const T &value, Targs &&... Args)
 Outputs variadic arguments to std::cout with formatting.
 
template<typename T >
void tec::println (const T &arg)
 Outputs a single argument to std::cout with a newline.
 
template<typename T , typename... Targs>
void tec::println (const char *fmt, const T &value, Targs &&... Args)
 Outputs variadic arguments to std::cout with formatting and a newline.
 
template<typename T >
std::string tec::format (const T &arg)
 Formats a single argument into a string.
 
template<typename T , typename... Targs>
std::string tec::format (const char *fmt, const T &value, Targs &&... Args)
 Formats variadic arguments into a string.
 

Detailed Description

Provides variadic print and format utilities for the tec namespace. Implemented for compatibility with pre-C++20 compilers.

Author
The Emacs Cat
Date
2025-09-17

Function Documentation

◆ format() [1/2]

template<typename T , typename... Targs>
std::string tec::format ( const char fmt,
const T value,
Targs &&...  Args 
)

Formats variadic arguments into a string.

Processes a format string with "{}" placeholders, replacing each placeholder with the corresponding argument, and returns the resulting string.

Template Parameters
TThe type of the first argument.
TargsThe types of additional arguments.
Parameters
fmtThe format string containing "{}" placeholders.
valueThe first argument to format.
ArgsThe remaining arguments to format.
Returns
std::string The formatted string.

◆ format() [2/2]

template<typename T >
std::string tec::format ( const T arg)

Formats a single argument into a string.

Converts the provided argument to its string representation using an output stream.

Template Parameters
TThe type of the argument to format.
Parameters
argThe argument to format.
Returns
std::string The string representation of the argument.

◆ print() [1/4]

template<typename T , typename... Targs>
void tec::print ( const char fmt,
const T value,
Targs &&...  Args 
)

Outputs variadic arguments to std::cout with formatting.

Processes a format string with "{}" placeholders, replacing each placeholder with the corresponding argument, outputting to the standard output stream.

Template Parameters
TThe type of the first argument.
TargsThe types of additional arguments.
Parameters
fmtThe format string containing "{}" placeholders.
valueThe first argument to output.
ArgsThe remaining arguments to output.

◆ print() [2/4]

template<typename T >
void tec::print ( const T arg)

Outputs a single argument to std::cout.

Writes the provided argument to the standard output stream without formatting.

Template Parameters
TThe type of the argument to output.
Parameters
argThe argument to output.

◆ print() [3/4]

template<typename T , typename... Targs>
void tec::print ( std::ostream *  out,
const char fmt,
const T value,
Targs &&...  Args 
)

Outputs variadic arguments to the specified stream with formatting.

Processes a format string with "{}" placeholders, replacing each placeholder with the corresponding argument. Recursively handles multiple arguments.

Template Parameters
TThe type of the first argument.
TargsThe types of additional arguments.
Parameters
outPointer to the output stream (e.g., std::cout or std::ostringstream).
fmtThe format string containing "{}" placeholders.
valueThe first argument to output.
ArgsThe remaining arguments to output.

◆ print() [4/4]

template<typename T >
void tec::print ( std::ostream *  out,
const T arg 
)

Outputs a single argument to the specified stream.

Writes the provided argument to the given output stream without any formatting.

Template Parameters
TThe type of the argument to output.
Parameters
outPointer to the output stream (e.g., std::cout or std::ostringstream).
argThe argument to output.

◆ println() [1/4]

template<typename T , typename... Targs>
void tec::println ( const char fmt,
const T value,
Targs &&...  Args 
)

Outputs variadic arguments to std::cout with formatting and a newline.

Processes a format string with "{}" placeholders, replacing each placeholder with the corresponding argument, outputting to the standard output stream, and appending a newline.

Template Parameters
TThe type of the first argument.
TargsThe types of additional arguments.
Parameters
fmtThe format string containing "{}" placeholders.
valueThe first argument to output.
ArgsThe remaining arguments to output.

◆ println() [2/4]

template<typename T >
void tec::println ( const T arg)

Outputs a single argument to std::cout with a newline.

Writes the provided argument to the standard output stream and appends a newline.

Template Parameters
TThe type of the argument to output.
Parameters
argThe argument to output.

◆ println() [3/4]

template<typename T , typename... Targs>
void tec::println ( std::ostream *  out,
const char fmt,
const T value,
Targs &&...  Args 
)

Outputs variadic arguments to the specified stream with formatting and a newline.

Processes a format string with "{}" placeholders, replacing each placeholder with the corresponding argument, and appends a newline at the end.

Template Parameters
TThe type of the first argument.
TargsThe types of additional arguments.
Parameters
outPointer to the output stream (e.g., std::cout or std::ostringstream).
fmtThe format string containing "{}" placeholders.
valueThe first argument to output.
ArgsThe remaining arguments to output.

◆ println() [4/4]

template<typename T >
void tec::println ( std::ostream *  out,
const T arg 
)

Outputs a single argument to the specified stream with a newline.

Writes the provided argument to the given output stream and appends a newline.

Template Parameters
TThe type of the argument to output.
Parameters
outPointer to the output stream (e.g., std::cout or std::ostringstream).
argThe argument to output.