玩弄C++ 11,我尝试构建一个函数,通过将任意对象写入一个来连接它们ostringstream.作为那些辅助函数,我有一个可变辅助函数,它将一个项目附加到现有函数ostream(下面的完整粘贴中给出的更多上下文):
template<class Head, class... Tail>
std::ostream& append(std::ostream& out, const Head& head, const Tail&... tail)
{
return append(out << head, tail...);
}
Run Code Online (Sandbox Code Playgroud)
但后来我认为可能有一些对象,当<<应用于流时,不会返回ostream而是返回一些占位符.因此,将流类型设置为模板参数也很酷:
1 #include <iostream>
2 #include <sstream>
3
4 template<typename Stream>
5 Stream& append(Stream& out) {
6 return out;
7 }
8
9 template<class Stream, class Head, class... Tail>
10 auto append(Stream& out, const Head& head, const Tail&... tail)
11 -> decltype(append(out << head, tail...)) // <<<<< This is the …Run Code Online (Sandbox Code Playgroud) 这是一个字符串:
str1="ha,hihi,aaaaa,ok"
Run Code Online (Sandbox Code Playgroud)
我想要得到的位置","中str1,这可以算3,8,14.
我怎么能在R中得到它?
假设我有一对相关的模板,我想自动将参数从一个函数转换为另一个函数.我怎样才能做到这一点?
template<int a> struct bar;
template<int a, int b> struct foo {
operator bar<a> const (); // operator-based conversion
};
template<int a> struct bar : public foo<a, a> {
bar() { }
template<int b> bar(const foo<a, b>&) { } // constructor-based conversion
};
template<int a, int b> foo<a, b>::operator bar<a> const () { return bar<a>(); }
template<int a> void f(bar<a> x, bar<a> y) { }
int main() {
bar<1> x;
foo<1, 2> y;
f(x, y);
}
Run Code Online (Sandbox Code Playgroud)
对此,gcc 4.8.3说:
template argument …Run Code Online (Sandbox Code Playgroud) 我有一个基于ant和ivy的项目,并且我还使用ivy来加载依赖项。由于某些原因,使用ant 1.9时,这些项目之一已开始报告一个奇怪的失败:
junit.framework.AssertionFailedError: No tests found in name.of.my.Clazz
Run Code Online (Sandbox Code Playgroud)
这很奇怪,因为我在类中使用JUnit4 @Test批注来批注测试方法,因此应该找到很多测试用例。