Fra*_*ank 1 c++ templates typedef namespaces function
我有一个模板化的函数fct,它使用一些基于模板参数的复杂数据结构.它还调用一些独立helpers命名空间中的辅助函数(模板化在同一类型上),并使用相同的复杂数据结构.现在它变得非常难看,因为我们无法typedef为所有函数都可以访问的复杂类型创建一个:
namespace helpers {
  template<class T>
  void h1(const std::vector< std::vector< std::map<T, std::set<T> > > >& bar){
    // ...
  }
}
template<class T>
void fct(const std::vector< std::vector< std::map<T, std::set<T> > > >& bar){
  // ...
  helpers::h1(bar);
}
现在我想通过使用一个所有函数都可以使用的typedef来使它更漂亮.
模板化typedef会很好,但不允许:
template<class T> 
typedef std::vector< std::vector< std::map<T, std::set<T> > > > Bar;
我认为另一个解决方案是将所有这些函数包装在模板中namespace,但在C++中也是不允许的(我听说它将在`C++ 0x'...中).
我们当然有模板化的类,但请注意,我并不是真的希望用户必须构造一个对象并在其上调用成员函数.所以我最终使用的解决方法是使用模板化的类,其中所有成员函数都是static:  
template<class T>
class All {
  typedef std::vector< std::vector< std::map<T, std::set<T> > > > Bar;
  static void fct(const Bar& bar){
    // ...
    h1(bar);
  }
private:
  static void h1(const Bar& bar){
    // ...
  }
};
我的问题是:如果我的代码的大部分内容是这样组织的,那可能有点滑稽?毕竟有很多只有静态成员函数的类有点不寻常吗?是否有其他解决方案/解决方法可以使"模板化typedef"/"模板化命名空间"成为可能?
| 归档时间: | 
 | 
| 查看次数: | 1709 次 | 
| 最近记录: |