Console Library 8.0.0
A header-only library that makes C++ simple
Loading...
Searching...
No Matches
console::Cow< T > Class Template Reference

写时复制数据类。 More...

#include <cow.h>

Public Member Functions

template<class... Args, class = typename std::enable_if< std::is_constructible<T, Args...>::value>::type>
 Cow (Args &&...args)
 构造函数,使用可变参数构造内部数据。
 Cow ()
 默认构造函数。
 Cow (const Cow &)=default
 默认的拷贝构造函数。
 Cow (Cow &&)=default
 默认的移动构造函数。
Cow & operator= (const Cow &)=default
 默认的拷贝赋值函数。
Cow & operator= (Cow &&)=default
 默认的移动赋值函数。
 Cow (const T &t)
 从已有对象拷贝构造 Cow。
 Cow (T &&t)
 从已有对象移动构造 Cow。
Cow & operator= (const T &t)
 赋值运算符。
Cow & operator= (T &&t)
 移动赋值运算符。
void detach ()
 分离内部数据,确保只有一个共享指针。
const T & reader () const
 读取数据的常量引用。
const T & r () const
 读取数据的常量引用。
T & writer ()
 获取数据的引用,用于写入操作。
T & w ()
 获取数据的引用,用于写入操作。
template<class F>
auto read (F &&f) const -> decltype(f(reader()))
 读取数据的通用函数。
template<class F>
auto r (F &&f) const -> decltype(f(r()))
 读取数据的通用函数。
template<class F>
auto write (F &&f) -> decltype(f(writer()))
 写入数据的通用函数。
template<class F>
auto w (F &&f) -> decltype(f(w()))
 写入数据的通用函数。
const std::shared_ptr< T > & data () const
 获取数据的共享指针。

Private Attributes

std::shared_ptr< T > data_
 内部数据指针。

Detailed Description

template<class T>
class console::Cow< T >

写时复制数据类。

Template Parameters
T数据类型。

Constructor & Destructor Documentation

◆ Cow() [1/6]

template<class T>
template<class... Args, class = typename std::enable_if< std::is_constructible<T, Args...>::value>::type>
console::Cow< T >::Cow ( Args &&... args)
inlineexplicit

构造函数,使用可变参数构造内部数据。

Template Parameters
Args构造函数参数类型。
Parameters
args构造函数参数。

◆ Cow() [2/6]

template<class T>
console::Cow< T >::Cow ( )
inlineexplicit

默认构造函数。

◆ Cow() [3/6]

template<class T>
console::Cow< T >::Cow ( const Cow< T > & )
default

默认的拷贝构造函数。

◆ Cow() [4/6]

template<class T>
console::Cow< T >::Cow ( Cow< T > && )
default

默认的移动构造函数。

◆ Cow() [5/6]

template<class T>
console::Cow< T >::Cow ( const T & t)
inline

从已有对象拷贝构造 Cow。

Parameters
t已有对象。

◆ Cow() [6/6]

template<class T>
console::Cow< T >::Cow ( T && t)
inline

从已有对象移动构造 Cow。

Parameters
t已有对象。

Member Function Documentation

◆ data()

template<class T>
const std::shared_ptr< T > & console::Cow< T >::data ( ) const
inline

获取数据的共享指针。

Returns
数据的共享指针。
Note
只读。

◆ detach()

template<class T>
void console::Cow< T >::detach ( )
inline

分离内部数据,确保只有一个共享指针。

Note
若已独立,则不复制任何东西。

◆ operator=() [1/4]

template<class T>
Cow & console::Cow< T >::operator= ( const Cow< T > & )
default

默认的拷贝赋值函数。

◆ operator=() [2/4]

template<class T>
Cow & console::Cow< T >::operator= ( const T & t)
inline

赋值运算符。

Parameters
t已有对象。
Returns
自身引用。

◆ operator=() [3/4]

template<class T>
Cow & console::Cow< T >::operator= ( Cow< T > && )
default

默认的移动赋值函数。

◆ operator=() [4/4]

template<class T>
Cow & console::Cow< T >::operator= ( T && t)
inline

移动赋值运算符。

Parameters
t已有对象。
Returns
自身引用。

◆ r() [1/2]

template<class T>
const T & console::Cow< T >::r ( ) const
inline

读取数据的常量引用。

Returns
数据的常量引用。

◆ r() [2/2]

template<class T>
template<class F>
auto console::Cow< T >::r ( F && f) const -> decltype(f(r()))
inline

读取数据的通用函数。

Template Parameters
F函数类型。
Parameters
f函数对象。
Returns
函数的返回值。

◆ read()

template<class T>
template<class F>
auto console::Cow< T >::read ( F && f) const -> decltype(f(reader()))
inline

读取数据的通用函数。

Template Parameters
F函数类型。
Parameters
f函数对象。
Returns
函数的返回值。

◆ reader()

template<class T>
const T & console::Cow< T >::reader ( ) const
inline

读取数据的常量引用。

Returns
数据的常量引用。

◆ w() [1/2]

template<class T>
T & console::Cow< T >::w ( )
inline

获取数据的引用,用于写入操作。

Returns
数据的引用。
Note
若可能,不要保留引用。

◆ w() [2/2]

template<class T>
template<class F>
auto console::Cow< T >::w ( F && f) -> decltype(f(w()))
inline

写入数据的通用函数。

Template Parameters
F函数类型。
Parameters
f函数对象。
Returns
函数的返回值。

◆ write()

template<class T>
template<class F>
auto console::Cow< T >::write ( F && f) -> decltype(f(writer()))
inline

写入数据的通用函数。

Template Parameters
F函数类型。
Parameters
f函数对象。
Returns
函数的返回值。

◆ writer()

template<class T>
T & console::Cow< T >::writer ( )
inline

获取数据的引用,用于写入操作。

Returns
数据的引用。
Note
若可能,不要保留引用。

Member Data Documentation

◆ data_

template<class T>
std::shared_ptr<T> console::Cow< T >::data_
private

内部数据指针。


The documentation for this class was generated from the following file:
  • include/container/cow.h