cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
toolbox::utils Namespace Reference

< 用于 std::out_of_range/For std::out_of_range More...

Namespaces

namespace  detail
 
namespace  impl
 
namespace  ini_detail
 

Classes

class  argument_t
 
class  array_printer_t
 Array 打印器/Array printer. More...
 
class  ClickException
 
class  color_handler_t
 平台无关的颜色处理类/Platform-independent color handler More...
 
class  command_t
 
class  CommandLineApp
 
class  container_printer_t
 通用容器打印器基类/Generic container printer base class More...
 
class  deque_printer_t
 Deque 打印器/Deque printer. More...
 
class  flag_t
 
class  ini_config_t
 
struct  ini_field_desc
 
struct  ini_struct_traits
 
class  list_printer_t
 List 打印器/List printer. More...
 
class  map_printer_t
 Map 打印器/Map printer. More...
 
class  option_t
 
class  parameter_t
 
class  ParameterError
 
class  plot_t
 
struct  print_style_t
 打印风格设置/Print style settings More...
 
class  queue_printer_t
 队列打印器/Queue printer More...
 
class  random_t
 随机数工具类/Random number utility class More...
 
class  set_printer_t
 Set 打印器/Set printer. More...
 
class  simple_timer_array_t
 Concrete implementation of simple_timer_interface_t using an array of timers. More...
 
class  simple_timer_interface_t
 Interface for managing a collection of timers. More...
 
class  stop_watch_timer_t
 A high-resolution stopwatch timer for measuring elapsed time. More...
 
class  table_t
 格式化打印表格工具/Formatted table printing utility More...
 
class  unorderedmap_printer_t
 Unordered Map 打印器/Unordered map printer. More...
 
class  unorderedset_printer_t
 Unordered Set 打印器/Unordered set printer. More...
 
class  UsageError
 
class  vector_printer_t
 Vector 打印器/Vector printer. More...
 

Functions

template<typename T_Optional >
bool parse_optional_value (const std::string &input, T_Optional &output)
 
template<typename Struct >
bool load_struct_from_ini (const ini_config_t &cfg, Struct &obj, const std::string &base_section="")
 
auto get_default_style () -> const print_style_t &
 获取默认打印风格/Get default print style
 
auto get_ascii_style () -> const print_style_t &
 获取 ASCII 风格的表格边框/Get ASCII style table borders
 
auto get_rounded_style () -> const print_style_t &
 获取圆角边框风格/Style using Unicode box drawing characters
 
template<typename T >
auto to_string_value (const T &value) -> std::string
 获取字符串表示形式的通用函数/Generic function to get string representation
 
auto align_text (const std::string &text, size_t width, align_t align, const std::string &padding=" ") -> std::string
 处理对齐功能/Handle text alignment
 
CPP_TOOLBOX_EXPORT std::ostream & operator<< (std::ostream &os, const table_t &tbl)
 
template<typename Container >
auto operator<< (std::ostream &os, const container_printer_t< Container > &printer) -> std::ostream &
 输出容器 / Output container
 
template<typename T >
auto print_vector (const std::vector< T > &vec, const std::string &name="Vector", const print_style_t &style=get_default_style()) -> vector_printer_t< T >
 打印vector的工厂函数/Factory function to print vector
 
template<typename K , typename V >
auto print_map (const std::map< K, V > &m, const std::string &name="Map", const print_style_t &style=get_default_style()) -> map_printer_t< K, V >
 打印map的工厂函数/Factory function to print map
 
template<typename K , typename V >
auto print_unordered_map (const std::unordered_map< K, V > &m, const std::string &name="Unordered Map", const print_style_t &style=get_default_style()) -> unorderedmap_printer_t< K, V >
 打印unordered_map的工厂函数/Factory function to print unordered_map
 
template<typename T >
auto print_set (const std::set< T > &s, const std::string &name="Set", const print_style_t &style=get_default_style()) -> set_printer_t< T >
 打印set的工厂函数/Factory function to print set
 
template<typename T >
auto print_unordered_set (const std::unordered_set< T > &s, const std::string &name="Unordered Set", const print_style_t &style=get_default_style()) -> unorderedset_printer_t< T >
 打印unordered_set的工厂函数/Factory function to print unordered_set
 
template<typename T >
auto print_deque (const std::deque< T > &d, const std::string &name="Deque", const print_style_t &style=get_default_style()) -> deque_printer_t< T >
 打印deque的工厂函数/Factory function to print deque
 
template<typename T >
auto print_list (const std::list< T > &l, const std::string &name="List", const print_style_t &style=get_default_style()) -> list_printer_t< T >
 打印list的工厂函数/Factory function to print list
 
template<typename T , size_t N>
auto print_array (const std::array< T, N > &arr, const std::string &name="Array", const print_style_t &style=get_default_style()) -> array_printer_t< T, N >
 打印array的工厂函数/Factory function to print array
 
template<typename T >
auto print_queue (const std::queue< T > &q, const std::string &name="Queue", const print_style_t &style=get_default_style()) -> queue_printer_t< T >
 打印queue的工厂函数/Factory function to print queue
 
int randint (int a, int b)
 生成[a, b]范围内的随机整数/Generate random integer in [a, b]
 
template<typename T >
random (T a, T b)
 通用随机数生成函数/General random number generator
 
template<typename T >
random ()
 无参数版本的随机数生成函数/Random number generator without parameters
 
template<typename T >
uniform (T a, T b)
 生成[a, b]范围内的均匀分布浮点数/Generate uniform random float in [a, b]
 
template<typename T >
gauss (T mu, T sigma)
 生成高斯分布(正态分布)随机数/Generate Gaussian (normal) distributed random number
 
template<typename T >
choice (const std::vector< T > &vec)
 从vector中随机选择一个元素/Randomly choose one element from vector
 
template<typename T >
std::vector< T > choice_n (const std::vector< T > &vec, size_t n)
 从vector中随机选择n个元素/Randomly choose n elements from vector
 
template<typename T >
std::vector< T > sample (const std::vector< T > &population, size_t k)
 从vector中随机采样k个元素/Randomly sample k elements from vector
 
template<typename TContainer >
TContainer::value_type choice (const TContainer &container)
 通用容器的随机选择/Randomly choose one element from general container
 
template<typename TContainer >
TContainer choice_n (const TContainer &container, size_t n)
 通用容器的随机选择n个元素/Randomly choose n elements from general container
 
template<typename TContainer >
TContainer sample (const TContainer &container, size_t n)
 通用容器的随机采样n个元素/Randomly sample n elements from general container
 
template<typename TContainer >
void shuffle (TContainer &container)
 随机打乱容器/Shuffle the container randomly
 
template<typename TContainer >
TContainer generate (std::size_t n, typename TContainer::value_type min, typename TContainer::value_type max)
 生成n个随机数/Generate n random numbers
 
auto create_timer (simple_timer_interface_t **timer_interface, int size) -> bool
 Create a timer collection with specified size.
 
auto create_timer_with_names (simple_timer_interface_t **timer_interface, const std::vector< std::string > &names) -> bool
 Create a timer collection with specified names.
 
auto delete_timer (simple_timer_interface_t **timer_interface) -> bool
 Delete a timer collection.
 
auto start_timer (simple_timer_interface_t **timer_interface, int id) -> bool
 Start a specific timer.
 
auto stop_timer (simple_timer_interface_t **timer_interface, int id) -> bool
 Stop a specific timer.
 
auto reset_timer (simple_timer_interface_t **timer_interface, int id) -> bool
 Reset a specific timer.
 
auto display_timer (simple_timer_interface_t **timer_interface, int id) -> bool
 Display statistics for a specific timer.
 
auto display_all_timer (simple_timer_interface_t **timer_interface) -> bool
 Display statistics for all timers.
 
auto get_timer_elapsed (simple_timer_interface_t **timer_interface, int id) -> double
 Get the elapsed time in seconds for a specific timer.
 
auto get_timer_elapsed_ms (simple_timer_interface_t **timer_interface, int id) -> double
 Get the elapsed time in milliseconds for a specific timer.
 

Variables

enum CPP_TOOLBOX_EXPORT align_t
 左对齐/Left align
 
enum CPP_TOOLBOX_EXPORT RIGHT
 右对齐/Right align
 
enum CPP_TOOLBOX_EXPORT CENTER
 < 居中对齐/Center align
 
enum CPP_TOOLBOX_EXPORT color_t
 默认颜色/Default color
 
enum CPP_TOOLBOX_EXPORT BLACK
 黑色/Black
 
enum CPP_TOOLBOX_EXPORT RED
 红色/Red
 
enum CPP_TOOLBOX_EXPORT GREEN
 绿色/Green
 
enum CPP_TOOLBOX_EXPORT YELLOW
 黄色/Yellow
 
enum CPP_TOOLBOX_EXPORT BLUE
 蓝色/Blue
 
enum CPP_TOOLBOX_EXPORT MAGENTA
 品红/Magenta
 
enum CPP_TOOLBOX_EXPORT CYAN
 青色/Cyan
 
enum CPP_TOOLBOX_EXPORT WHITE
 < 白色/White
 
class CPP_TOOLBOX_EXPORT table_t
 

Detailed Description

< 用于 std::out_of_range/For std::out_of_range

< 用于 std::shuffle, std::sample/For std::shuffle, std::sample 用于种子生成/For seeding if not using random_device for every construction 用于 std::back_inserter/For std::back_inserter 用于 std::numeric_limits/For std::numeric_limits

Function Documentation

◆ align_text()

auto toolbox::utils::align_text ( const std::string &  text,
size_t  width,
align_t  align,
const std::string &  padding = " " 
) -> std::string
inline

处理对齐功能/Handle text alignment

Parameters
text输入文本/Input text
width目标宽度/Target width
align对齐方式/Alignment
padding填充字符/Padding character
Returns
std::string 对齐后的文本/Aligned text
std::string s = align_text("abc", 6, align_t::RIGHT); // " abc"
auto align_text(const std::string &text, size_t width, align_t align, const std::string &padding=" ") -> std::string
处理对齐功能/Handle text alignment
Definition print.hpp:404

◆ choice() [1/2]

template<typename T >
T toolbox::utils::choice ( const std::vector< T > &  vec)
inline

从vector中随机选择一个元素/Randomly choose one element from vector

Template Parameters
T元素类型/Element type
Parameters
vec输入vector/Input vector
Returns
T 随机元素/Random element
std::vector<int> v = {1,2,3};
T choice(const std::vector< T > &vec)
从vector中随机选择一个元素/Randomly choose one element from vector
Definition random.hpp:484

◆ choice() [2/2]

template<typename TContainer >
TContainer::value_type toolbox::utils::choice ( const TContainer &  container)
inline

通用容器的随机选择/Randomly choose one element from general container

Template Parameters
TContainer容器类型/Container type
Parameters
container输入容器/Input container
Returns
typename TContainer::value_type 随机元素/Random element
std::list<int> l = {1,2,3};

◆ choice_n() [1/2]

template<typename T >
std::vector< T > toolbox::utils::choice_n ( const std::vector< T > &  vec,
size_t  n 
)
inline

从vector中随机选择n个元素/Randomly choose n elements from vector

Template Parameters
T元素类型/Element type
Parameters
vec输入vector/Input vector
n选择数量/Number of elements to choose
Returns
std::vector<T> 结果/Result vector
std::vector<int> v = {1,2,3,4,5};
auto s = toolbox::utils::choice_n(v, 3);
std::vector< T > choice_n(const std::vector< T > &vec, size_t n)
从vector中随机选择n个元素/Randomly choose n elements from vector
Definition random.hpp:501

◆ choice_n() [2/2]

template<typename TContainer >
TContainer toolbox::utils::choice_n ( const TContainer &  container,
size_t  n 
)
inline

通用容器的随机选择n个元素/Randomly choose n elements from general container

Template Parameters
TContainer容器类型/Container type
Parameters
container输入容器/Input container
n选择数量/Number of elements to choose
Returns
TContainer 结果/Result container
std::set<int> s = {1,2,3,4,5};
auto r = toolbox::utils::choice_n(s, 2);

◆ create_timer()

auto toolbox::utils::create_timer ( simple_timer_interface_t **  timer_interface,
int  size 
) -> bool
inline

Create a timer collection with specified size.

Parameters
timer_interfacePointer to store the created interface
sizeNumber of timers to create
Returns
true if creation succeeded, false otherwise
create_timer(&timers, 3);
Interface for managing a collection of timers.
Definition timer.hpp:127
auto create_timer(simple_timer_interface_t **timer_interface, int size) -> bool
Create a timer collection with specified size.
Definition timer.hpp:260

◆ create_timer_with_names()

auto toolbox::utils::create_timer_with_names ( simple_timer_interface_t **  timer_interface,
const std::vector< std::string > &  names 
) -> bool
inline

Create a timer collection with specified names.

Parameters
timer_interfacePointer to store the created interface
namesVector of names for each timer
Returns
true if creation succeeded, false otherwise
std::vector<std::string> names = {"timer1", "timer2", "timer3"};
create_timer_with_names(&timers, names);
auto create_timer_with_names(simple_timer_interface_t **timer_interface, const std::vector< std::string > &names) -> bool
Create a timer collection with specified names.
Definition timer.hpp:280

◆ delete_timer()

auto toolbox::utils::delete_timer ( simple_timer_interface_t **  timer_interface) -> bool
inline

Delete a timer collection.

Parameters
timer_interfacePointer to the interface to delete
Returns
true if deletion succeeded, false otherwise
create_timer(&timers, 3);
// ... use timers ...
delete_timer(&timers);
auto delete_timer(simple_timer_interface_t **timer_interface) -> bool
Delete a timer collection.
Definition timer.hpp:301

◆ display_all_timer()

auto toolbox::utils::display_all_timer ( simple_timer_interface_t **  timer_interface) -> bool
inline

Display statistics for all timers.

Parameters
timer_interfacePointer to the timer interface
Returns
true if operation succeeded, false otherwise
start_timer(&timers, 0);
// ... perform operation ...
auto display_all_timer(simple_timer_interface_t **timer_interface) -> bool
Display statistics for all timers.
Definition timer.hpp:411
auto start_timer(simple_timer_interface_t **timer_interface, int id) -> bool
Start a specific timer.
Definition timer.hpp:322

◆ display_timer()

auto toolbox::utils::display_timer ( simple_timer_interface_t **  timer_interface,
int  id 
) -> bool
inline

Display statistics for a specific timer.

Parameters
timer_interfacePointer to the timer interface
idIndex of the timer to display
Returns
true if operation succeeded, false otherwise
create_timer(&timers, 3);
start_timer(&timers, 0);
// ... perform operation ...
display_timer(&timers, 0);
auto display_timer(simple_timer_interface_t **timer_interface, int id) -> bool
Display statistics for a specific timer.
Definition timer.hpp:391

◆ gauss()

template<typename T >
T toolbox::utils::gauss ( mu,
sigma 
)
inline

生成高斯分布(正态分布)随机数/Generate Gaussian (normal) distributed random number

Template Parameters
T浮点类型/Floating point type
Parameters
mu均值/Mean
sigma标准差/Standard deviation
Returns
T 随机数/Random value
float g = toolbox::utils::gauss<float>(0.0f, 1.0f);

◆ generate()

template<typename TContainer >
TContainer toolbox::utils::generate ( std::size_t  n,
typename TContainer::value_type  min,
typename TContainer::value_type  max 
)
inline

生成n个随机数/Generate n random numbers

Template Parameters
TContainer容器类型/Container type
Parameters
n生成数量/Number of random numbers
min下界/Lower bound
max上界/Upper bound
Returns
TContainer 随机数容器/Container of random numbers
auto r = toolbox::utils::generate<std::vector<int>>(10, 1, 100);
auto f = toolbox::utils::generate<std::vector<float>>(10, 0.0f, 1.0f);
auto d = toolbox::utils::generate<std::list<double>>(10, 0.0, 1.0);
auto i = toolbox::utils::generate<std::deque<int>>(10, 1, 100);

◆ get_ascii_style()

auto toolbox::utils::get_ascii_style ( ) -> const print_style_t&
inline

获取 ASCII 风格的表格边框/Get ASCII style table borders

Returns
const print_style_t& ASCII 风格引用/Reference to ASCII style
const auto& style = toolbox::utils::get_ascii_style();
auto get_ascii_style() -> const print_style_t &
获取 ASCII 风格的表格边框/Get ASCII style table borders
Definition print.hpp:121

◆ get_default_style()

auto toolbox::utils::get_default_style ( ) -> const print_style_t&
inline

获取默认打印风格/Get default print style

Returns
const print_style_t& 默认风格引用/Reference to default style
const auto& style = toolbox::utils::get_default_style();
auto get_default_style() -> const print_style_t &
获取默认打印风格/Get default print style
Definition print.hpp:108

◆ get_rounded_style()

auto toolbox::utils::get_rounded_style ( ) -> const print_style_t&
inline

获取圆角边框风格/Style using Unicode box drawing characters

◆ get_timer_elapsed()

auto toolbox::utils::get_timer_elapsed ( simple_timer_interface_t **  timer_interface,
int  id 
) -> double
inline

Get the elapsed time in seconds for a specific timer.

Parameters
timer_interfacePointer to the timer interface
idIndex of the timer to query
Returns
Elapsed time in seconds. Returns 0.0 if timer_interface is null
// Basic usage
create_timer(&timers, 3);
start_timer(&timers, 0);
// ... perform operation ...
double elapsed_seconds = get_timer_elapsed(&timers, 0);
// Safe usage with null check
simple_timer_interface_t* timers = nullptr;
double elapsed = get_timer_elapsed(&timers, 0); // Returns 0.0
auto get_timer_elapsed(simple_timer_interface_t **timer_interface, int id) -> double
Get the elapsed time in seconds for a specific timer.
Definition timer.hpp:439

◆ get_timer_elapsed_ms()

auto toolbox::utils::get_timer_elapsed_ms ( simple_timer_interface_t **  timer_interface,
int  id 
) -> double
inline

Get the elapsed time in milliseconds for a specific timer.

Parameters
timer_interfacePointer to the timer interface
idIndex of the timer to query
Returns
Elapsed time in milliseconds. Returns 0.0 if timer_interface is null
// Basic usage
create_timer(&timers, 3);
start_timer(&timers, 0);
// ... perform operation ...
double elapsed_ms = get_timer_elapsed_ms(&timers, 0);
// Comparing seconds and milliseconds
create_timer(&timers, 1);
start_timer(&timers, 0);
std::this_thread::sleep_for(std::chrono::milliseconds(1500));
stop_timer(&timers, 0);
double seconds = get_timer_elapsed(&timers, 0); // ~1.5 seconds
double milliseconds = get_timer_elapsed_ms(&timers, 0); // ~1500.0 ms
auto get_timer_elapsed_ms(simple_timer_interface_t **timer_interface, int id) -> double
Get the elapsed time in milliseconds for a specific timer.
Definition timer.hpp:472
auto stop_timer(simple_timer_interface_t **timer_interface, int id) -> bool
Stop a specific timer.
Definition timer.hpp:345

◆ load_struct_from_ini()

template<typename Struct >
bool toolbox::utils::load_struct_from_ini ( const ini_config_t cfg,
Struct &  obj,
const std::string &  base_section = "" 
)

◆ operator<<() [1/2]

template<typename Container >
auto toolbox::utils::operator<< ( std::ostream &  os,
const container_printer_t< Container > &  printer 
) -> std::ostream&

输出容器 / Output container

Template Parameters
Container容器类型 / Container type
Parameters
os输出流 / Output stream
printer打印器 / Printer
Returns
std::ostream& 输出流引用 / Reference to output stream
std::cout << print_vector(vec);
auto print_vector(const std::vector< T > &vec, const std::string &name="Vector", const print_style_t &style=get_default_style()) -> vector_printer_t< T >
打印vector的工厂函数/Factory function to print vector
Definition print.hpp:1525

◆ operator<<() [2/2]

CPP_TOOLBOX_EXPORT std::ostream & toolbox::utils::operator<< ( std::ostream &  os,
const table_t tbl 
)
Parameters
os输出流 / Output stream
tbl要打印的table_t对象 / Table object to print
Returns
std::ostream& 输出流引用 / Reference to output stream

◆ parse_optional_value()

template<typename T_Optional >
bool toolbox::utils::parse_optional_value ( const std::string &  input,
T_Optional &  output 
)

◆ print_array()

template<typename T , size_t N>
auto toolbox::utils::print_array ( const std::array< T, N > &  arr,
const std::string &  name = "Array",
const print_style_t style = get_default_style() 
) -> array_printer_t<T, N>

打印array的工厂函数/Factory function to print array

Template Parameters
T元素类型/Element type
N数组大小/Array size
Parameters
arrarray对象/Array object
name名称/Name
style打印风格/Print style
Returns
array_printer_t<T,N> 打印器/Printer
std::array<int,2> arr{{1,2}};
std::cout << print_array(arr);
auto print_array(const std::array< T, N > &arr, const std::string &name="Array", const print_style_t &style=get_default_style()) -> array_printer_t< T, N >
打印array的工厂函数/Factory function to print array
Definition print.hpp:1675

◆ print_deque()

template<typename T >
auto toolbox::utils::print_deque ( const std::deque< T > &  d,
const std::string &  name = "Deque",
const print_style_t style = get_default_style() 
) -> deque_printer_t<T>

打印deque的工厂函数/Factory function to print deque

Template Parameters
T元素类型/Element type
Parameters
ddeque对象/Deque object
name名称/Name
style打印风格/Print style
Returns
deque_printer_t<T> 打印器/Printer
std::deque<int> d{1,2};
std::cout << print_deque(d);
auto print_deque(const std::deque< T > &d, const std::string &name="Deque", const print_style_t &style=get_default_style()) -> deque_printer_t< T >
打印deque的工厂函数/Factory function to print deque
Definition print.hpp:1632

◆ print_list()

template<typename T >
auto toolbox::utils::print_list ( const std::list< T > &  l,
const std::string &  name = "List",
const print_style_t style = get_default_style() 
) -> list_printer_t<T>

打印list的工厂函数/Factory function to print list

Template Parameters
T元素类型/Element type
Parameters
llist对象/List object
name名称/Name
style打印风格/Print style
Returns
list_printer_t<T> 打印器/Printer
std::list<int> l{1,2};
std::cout << print_list(l);
auto print_list(const std::list< T > &l, const std::string &name="List", const print_style_t &style=get_default_style()) -> list_printer_t< T >
打印list的工厂函数/Factory function to print list
Definition print.hpp:1653

◆ print_map()

template<typename K , typename V >
auto toolbox::utils::print_map ( const std::map< K, V > &  m,
const std::string &  name = "Map",
const print_style_t style = get_default_style() 
) -> map_printer_t<K, V>

打印map的工厂函数/Factory function to print map

Template Parameters
K键类型/Key type
V值类型/Value type
Parameters
mmap对象/Map object
name名称/Name
style打印风格/Print style
Returns
map_printer_t<K,V> 打印器/Printer
std::map<int,int> m{{1,2}};
std::cout << print_map(m);
auto print_map(const std::map< K, V > &m, const std::string &name="Map", const print_style_t &style=get_default_style()) -> map_printer_t< K, V >
打印map的工厂函数/Factory function to print map
Definition print.hpp:1547

◆ print_queue()

template<typename T >
auto toolbox::utils::print_queue ( const std::queue< T > &  q,
const std::string &  name = "Queue",
const print_style_t style = get_default_style() 
) -> queue_printer_t<T>

打印queue的工厂函数/Factory function to print queue

Template Parameters
T队列元素类型/Element type of the queue
Parameters
qqueue对象/Queue object
name名称/Name
style打印风格/Print style
Returns
queue_printer_t<T> 打印器/Printer
std::queue<int> q;
q.push(10); q.push(20); q.push(30);
std::cout << print_queue(q, "MyQueue");
auto print_queue(const std::queue< T > &q, const std::string &name="Queue", const print_style_t &style=get_default_style()) -> queue_printer_t< T >
打印queue的工厂函数/Factory function to print queue
Definition print.hpp:1697

◆ print_set()

template<typename T >
auto toolbox::utils::print_set ( const std::set< T > &  s,
const std::string &  name = "Set",
const print_style_t style = get_default_style() 
) -> set_printer_t<T>

打印set的工厂函数/Factory function to print set

Template Parameters
T元素类型/Element type
Parameters
sset对象/Set object
name名称/Name
style打印风格/Print style
Returns
set_printer_t<T> 打印器/Printer
std::set<int> s{1,2};
std::cout << print_set(s);
auto print_set(const std::set< T > &s, const std::string &name="Set", const print_style_t &style=get_default_style()) -> set_printer_t< T >
打印set的工厂函数/Factory function to print set
Definition print.hpp:1590

◆ print_unordered_map()

template<typename K , typename V >
auto toolbox::utils::print_unordered_map ( const std::unordered_map< K, V > &  m,
const std::string &  name = "Unordered Map",
const print_style_t style = get_default_style() 
) -> unorderedmap_printer_t<K, V>

打印unordered_map的工厂函数/Factory function to print unordered_map

Template Parameters
K键类型/Key type
V值类型/Value type
Parameters
munordered_map对象/Unordered map object
name名称/Name
style打印风格/Print style
Returns
unorderedmap_printer_t<K,V> 打印器/Printer
std::unordered_map<int,int> m{{1,2}};
std::cout << print_unordered_map(m);
auto print_unordered_map(const std::unordered_map< K, V > &m, const std::string &name="Unordered Map", const print_style_t &style=get_default_style()) -> unorderedmap_printer_t< K, V >
打印unordered_map的工厂函数/Factory function to print unordered_map
Definition print.hpp:1569

◆ print_unordered_set()

template<typename T >
auto toolbox::utils::print_unordered_set ( const std::unordered_set< T > &  s,
const std::string &  name = "Unordered Set",
const print_style_t style = get_default_style() 
) -> unorderedset_printer_t<T>

打印unordered_set的工厂函数/Factory function to print unordered_set

Template Parameters
T元素类型/Element type
Parameters
sunordered_set对象/Unordered set object
name名称/Name
style打印风格/Print style
Returns
unorderedset_printer_t<T> 打印器/Printer
std::unordered_set<int> s{1,2};
std::cout << print_unordered_set(s);
auto print_unordered_set(const std::unordered_set< T > &s, const std::string &name="Unordered Set", const print_style_t &style=get_default_style()) -> unorderedset_printer_t< T >
打印unordered_set的工厂函数/Factory function to print unordered_set
Definition print.hpp:1611

◆ print_vector()

template<typename T >
auto toolbox::utils::print_vector ( const std::vector< T > &  vec,
const std::string &  name = "Vector",
const print_style_t style = get_default_style() 
) -> vector_printer_t<T>

打印vector的工厂函数/Factory function to print vector

Template Parameters
T元素类型/Element type
Parameters
vecvector对象/Vector object
name名称/Name
style打印风格/Print style
Returns
vector_printer_t<T> 打印器/Printer
std::vector<int> v{1,2,3};
std::cout << print_vector(v, "MyVec");

◆ randint()

int toolbox::utils::randint ( int  a,
int  b 
)
inline

生成[a, b]范围内的随机整数/Generate random integer in [a, b]

Parameters
a下界/Lower bound
b上界/Upper bound
Returns
int 随机整数/Random integer
int r = toolbox::utils::randint(1, 10);
int randint(int a, int b)
生成[a, b]范围内的随机整数/Generate random integer in [a, b]
Definition random.hpp:392

◆ random() [1/2]

template<typename T >
T toolbox::utils::random ( )
inline

无参数版本的随机数生成函数/Random number generator without parameters

Template Parameters
T类型/Type
Returns
T 随机数/Random value
int r = toolbox::utils::random<int>();
float f = toolbox::utils::random<float>();

◆ random() [2/2]

template<typename T >
T toolbox::utils::random ( a,
b 
)
inline

通用随机数生成函数/General random number generator

Template Parameters
T类型/Type
Parameters
a下界/Lower bound
b上界/Upper bound
Returns
T 随机数/Random value
auto r = toolbox::utils::random<int>(1, 10);
auto f = toolbox::utils::random<float>(0.0f, 1.0f);

◆ reset_timer()

auto toolbox::utils::reset_timer ( simple_timer_interface_t **  timer_interface,
int  id 
) -> bool
inline

Reset a specific timer.

Parameters
timer_interfacePointer to the timer interface
idIndex of the timer to reset
Returns
true if operation succeeded, false otherwise
create_timer(&timers, 3);
start_timer(&timers, 0);
// ... perform operation ...
reset_timer(&timers, 0);
auto reset_timer(simple_timer_interface_t **timer_interface, int id) -> bool
Reset a specific timer.
Definition timer.hpp:368

◆ sample() [1/2]

template<typename T >
std::vector< T > toolbox::utils::sample ( const std::vector< T > &  population,
size_t  k 
)
inline

从vector中随机采样k个元素/Randomly sample k elements from vector

Template Parameters
T元素类型/Element type
Parameters
population输入vector/Input vector
k采样数量/Number of samples
Returns
std::vector<T> 采样结果/Sampled vector
std::vector<int> v = {1,2,3,4,5};
auto s = toolbox::utils::sample(v, 2);
std::vector< T > sample(const std::vector< T > &population, size_t k)
从vector中随机采样k个元素/Randomly sample k elements from vector
Definition random.hpp:518

◆ sample() [2/2]

template<typename TContainer >
TContainer toolbox::utils::sample ( const TContainer &  container,
size_t  n 
)
inline

通用容器的随机采样n个元素/Randomly sample n elements from general container

Template Parameters
TContainer容器类型/Container type
Parameters
container输入容器/Input container
n采样数量/Number of samples
Returns
TContainer 采样结果/Sampled container
std::vector<int> v = {1,2,3,4,5};
auto s = toolbox::utils::sample(v, 3);

◆ shuffle()

template<typename TContainer >
void toolbox::utils::shuffle ( TContainer &  container)
inline

随机打乱容器/Shuffle the container randomly

Template Parameters
TContainer容器类型/Container type
Parameters
container输入容器/Input container
std::vector<int> v = {1,2,3};
void shuffle(TContainer &container)
随机打乱容器/Shuffle the container randomly
Definition random.hpp:594

◆ start_timer()

auto toolbox::utils::start_timer ( simple_timer_interface_t **  timer_interface,
int  id 
) -> bool
inline

Start a specific timer.

Parameters
timer_interfacePointer to the timer interface
idIndex of the timer to start
Returns
true if operation succeeded, false otherwise
create_timer(&timers, 3);
start_timer(&timers, 0);

◆ stop_timer()

auto toolbox::utils::stop_timer ( simple_timer_interface_t **  timer_interface,
int  id 
) -> bool
inline

Stop a specific timer.

Parameters
timer_interfacePointer to the timer interface
idIndex of the timer to stop
Returns
true if operation succeeded, false otherwise
create_timer(&timers, 3);
start_timer(&timers, 0);
// ... perform operation ...
stop_timer(&timers, 0);

◆ to_string_value()

template<typename T >
auto toolbox::utils::to_string_value ( const T &  value) -> std::string

获取字符串表示形式的通用函数/Generic function to get string representation

Template Parameters
T任意类型/Any type
Parameters
value输入值/Input value
Returns
std::string 字符串/String
std::string s = to_string_value(123); // "123"
auto to_string_value(const T &value) -> std::string
获取字符串表示形式的通用函数/Generic function to get string representation
Definition print.hpp:363

◆ uniform()

template<typename T >
T toolbox::utils::uniform ( a,
b 
)
inline

生成[a, b]范围内的均匀分布浮点数/Generate uniform random float in [a, b]

Template Parameters
T浮点类型/Floating point type
Parameters
a下界/Lower bound
b上界/Upper bound
Returns
T 随机浮点数/Random float
double f = toolbox::utils::uniform<double>(0.0, 10.0);

Variable Documentation

◆ align_t

enum CPP_TOOLBOX_EXPORT toolbox::utils::align_t
strong

左对齐/Left align

◆ BLACK

enum CPP_TOOLBOX_EXPORT toolbox::utils::BLACK

黑色/Black

◆ BLUE

enum CPP_TOOLBOX_EXPORT toolbox::utils::BLUE

蓝色/Blue

◆ CENTER

enum CPP_TOOLBOX_EXPORT toolbox::utils::CENTER

< 居中对齐/Center align

◆ color_t

enum CPP_TOOLBOX_EXPORT toolbox::utils::color_t
strong

默认颜色/Default color

◆ CYAN

enum CPP_TOOLBOX_EXPORT toolbox::utils::CYAN

青色/Cyan

◆ GREEN

enum CPP_TOOLBOX_EXPORT toolbox::utils::GREEN

绿色/Green

◆ MAGENTA

enum CPP_TOOLBOX_EXPORT toolbox::utils::MAGENTA

品红/Magenta

◆ RED

enum CPP_TOOLBOX_EXPORT toolbox::utils::RED

红色/Red

◆ RIGHT

enum CPP_TOOLBOX_EXPORT toolbox::utils::RIGHT

右对齐/Right align

◆ table_t

class CPP_TOOLBOX_EXPORT toolbox::utils::table_t

◆ WHITE

enum CPP_TOOLBOX_EXPORT toolbox::utils::WHITE

< 白色/White

◆ YELLOW

enum CPP_TOOLBOX_EXPORT toolbox::utils::YELLOW

黄色/Yellow