如何泛化接口以要求某个元组的返回值
how to generalize an interface to require a return value of some tuple?
我正在使用SOCI库,它对boost和std::tuple<>有很好的支持。
我的目的是定义一个名为SOCI_Streamable
的抽象接口,它需要一个返回一些元组的方法。
我让它适用于 gcc 4.7.2 中的特定元组,但我需要帮助抽象此接口以适用于任何元组。
换句话说,我想将此要求转换为代码:一个类满足SOCI_Streamable
的要求,如果它可以返回某种 std::tuple - 我不在乎哪种。
下面的代码进行重大更改是可以的,只要它满足要求。 我怀疑需要某种模板代码甚至 CRTP,但我不确定。
#include<tuple>
// want to generalize next line to any std::tuple<>
typedef std::tuple<int const&,char const> some_tuple;
class SOCI_Streamable
{
public:
virtual some_tuple obj_as_tuple() const = 0;
};
class Foo :
public SOCI_Streamable
{
public:
virtual some_tuple obj_as_tuple() const
{
return std::forward_as_tuple( m_int, m_char );
}
private:
int m_int;
char m_char;
};
int main( int argc, char* argv[] )
{
}
template <class A,class B>
class SOCI_Streamable
{
public:
typedef std::tuple<A,B> Tuple;
virtual Tuple obj_as_tuple() const = 0;
};
class Foo :
public SOCI_Streamable<int const&,char const>
{
如果可以在实现者级别指定类型,这应该可以工作。但这确实将单个接口更改为一系列接口。让我看看是否有更好的方法.
相关文章:
- 使用函数的元组返回多个值的问题
- 元组布尔值不会更改
- 从类型元组到通过调用模板函数返回的值数组
- 使用单参数模板化构造函数,从引用元组构造值元组
- 带有映射的 Lambda 函数,其中键是元组,值是双精度
- 为引用元组赋值
- 将函数的返回值存储在元组中
- C++返回具有类型名称值的元组的模板
- 如何泛化接口以要求某个元组的返回值
- 将函数元组应用于值并返回元组
- C++:如何通过异常处理从越界数组返回值
- 元组作为一种返回类型,是经过优化的未处理值
- 元组/领带的返回值优化
- 使用自动 c++ 检索存储元组的值
- 成员初始值设定项列表:从返回元组的函数初始化两个成员
- 返回带推理的值的泛型长度元组
- 如何使用boost元组返回两个向量
- 从并行数组返回值,并在以后的函数中使用这些值
- 通过ENUM查找返回元组值(不同类型)的模板函数
- 如何在gsoap中使字符串数组返回值