more dependent types with variadic templates

This follows yesterday's question, where I gave some C++ code that Visual Studio 2013 couldn't handle, and @galop1n kindly provided a workaround, which worked perfectly for that case. But now I've gone a tiny bit further and Visual Studio is giving me grief again. template <typename T> using ValueType = typename T::value_type; template<typename... Containers> void foo(c

使用可变参数模板的更多依赖类型

这遵循了昨天的问题,我提供了Visual Studio 2013无法处理的一些C ++代码,并且@ galop1n提供了一种解决方法,该解决方案适用于这种情况。 但是现在我已经走得更远了,Visual Studio再次让我感到悲伤。 template <typename T> using ValueType = typename T::value_type; template<typename... Containers> void foo(const Containers &...args) { std::tuple<ValueType<Containers>...> x; }

c++ template class member function specialization

I have a problem where I want to specialize a template member function of a template class in the code below. The answer to this question explicit specialization of template class member function seems to suggest that it can't be done. Is that correct, and if so, is there any work around I can use so that by inline inc functions get expanded at compile time? Many thanks! #include <ios

c ++模板类成员函数专业化

我有一个问题,我想在下面的代码中专门化模板类的模板成员函数。 这个问题的答案显式专门化模板类成员函数似乎表明它不能完成。 这是否正确,如果有的话,是否有任何解决方法可以使用,以便通过内联inc函数在编译时扩展? 非常感谢! #include <iostream> #include <cstdio> template <class IT, unsigned int N> struct IdxIterator { private: int startIdx[N], endIdx[N]; int curIdx[N]; IT

Visual C++ 2010, rvalue reference bug?

As I understand it (and I may not be completely right; the specification is a bit complicated), the template type deduction rules conspire against you. The compiler first attempts to substitute all templates (it's not choosing at this point yet—just looking for options) and gets: T const &r matches int lvalue with T = int , creating f(int const &) T &&r matches int lvalu

Visual C ++ 2010,右值引用错误?

据我了解(我可能不完全正确;规范有点复杂),模板类型的扣除规则与您合谋。 编译器首先尝试替换所有模板(它现在还没有选择 - 只是寻找选项),并得到: T const &r与T = int匹配int lvalue,创建f(int const &) T &&r将int lvalue与T = int&和int & &&缩减为int& ,从而创建f(int &) (规范中说明了这一点)。 现在谈到选择正确的过载和后来更好的匹配,因为第一个不同的cv资

type parameters to (function) templates ordered?

I am hosting SpiderMonkey in a current project and would like to have template functions generate some of the simple property get/set methods, eg: template <typename TClassImpl, int32 TClassImpl::*mem> JSBool JS_DLL_CALLBACK WriteProp(JSContext* cx, JSObject* obj, jsval id, jsval* vp) { if (TClassImpl* pImpl = (TClassImpl*)::JS_GetInstancePrivate(cx, obj, &TClassImpl::s_JsClass, NU

键入参数到(功能)模板排序?

我在当前项目中托管SpiderMonkey,并希望模板函数生成一些简单的属性get / set方法,例如: template <typename TClassImpl, int32 TClassImpl::*mem> JSBool JS_DLL_CALLBACK WriteProp(JSContext* cx, JSObject* obj, jsval id, jsval* vp) { if (TClassImpl* pImpl = (TClassImpl*)::JS_GetInstancePrivate(cx, obj, &TClassImpl::s_JsClass, NULL)) return ::JS_ValueToInt32(cx, *vp, &(pImpl-&g

Why decltype expressions in return types have to be mangled in the symbol name?

I recently found out that decltype expressions are mangled as part of the functions symbol names, when used as return types, and that this can be the cause of nasty segmentation faults while demangling the expressions (in debugging sessions for example), if the expression is too complex. The first version, using decltype in function return type, where the full expression gets mangled (http://go

为什么返回类型中的decltype表达式必须在符号名称中被改变?

我最近发现decltype表达式被当作函数符号名称的一部分,当用作返回类型时,它会成为令人讨厌的分段错误的原因,同时对表达式进行解构(例如在调试会话中),如果表达式是太复杂了。 第一个版本在函数返回类型中使用decltype,其中完整表达式被破坏(http://goo.gl/EALubx): #include <cstdint> #include <utility> struct A { void bar() const; }; template<typename T> decltype(std::declval<T>

Capture function argument type from actual arguments

Is it possible to capture the type of a formal argument, having only the function name and the actual arguments? I would need something similar to decltype, but it should return the function type instead of the return type of the function. I found a half solution with C++11. If the function is not overloaded, you can use decltype to get the signature, specifying only the function name and te

从实际参数捕获函数参数类型

是否有可能捕获正式参数的类型,只有函数名称和实际参数? 我需要类似于decltype的东西,但它应该返回函数类型而不是函数的返回类型。 我用C ++ 11找到了一个半解决方案。 如果该函数未被重载,则可以使用decltype来获取签名,仅指定函数名称和模板参数(如果有),但不指定实际参数: template<class F> struct my_function_traits; // function pointer template<class R, class Arg> struct my_function_tr

Using auto and decltype to return reference from function in templated class

How can I coerce a function in a templated class to return a reference to a member variable using auto/decltype? Here's a trivialized example of what I'm trying to do. Suppose you've got a templated class that stores something in a private member variable, a_ as follows: #include <iostream> template <typename T> class A { private: T a_; public: A(T a) : a_(a) {}

使用auto和decltype从模板类中的函数返回引用

如何强制模板类中的函数使用auto / decltype返回对成员变量的引用? 这是我想要做的一个简单的例子。 假设你有一个模板类,它将一些东西存储在私有成员变量a_ ,如下所示: #include <iostream> template <typename T> class A { private: T a_; public: A(T a) : a_(a) {} // 1. Return const reference to a_ const T & get() const { return a_; } // 2. Return non-const reference to a_

Specialize function template with decltype trailing return type

In C++11, how can I specialise a function template which is declared with a "complicated" trailing return type using decltype? The following works in GCC but produces "error C2912: explicit specialisation 'int f(void)' is not a specialisation of a function template" in VC2013: #include <iostream> int myint() { return 1; } template<class T> auto f() ->

专用具有decltype追踪返回类型的函数模板

在C ++ 11中,我怎样才能专门化一个使用decltype用“复杂”尾随返回类型声明的函数模板? 下面的代码在GCC中工作,但在VC2013中产生“错误C2912:显式专用化”int f(void)'不是函数模板的专门化“ #include <iostream> int myint() { return 1; } template<class T> auto f() -> decltype(myint()) // this seems to cause problems { std::cout << "generaln"; return 1; } template <>

C++11 compiler error when using decltype(var) followed by internal type of "var"

I'm using Visual C++ 2010, and here's my code snippet: std::set<int> s; decltype(s)::value_type param = 0; I got the following error message, anyone can help me? > error C2039: 'value_type' : is not a member of '`global namespace'' > error C2146: syntax error : missing ';' before identifier 'param' This is a Visual Studio bug that was raised last year on Connect. It is is

使用decltype(var)后跟内部类型“var”的C ++ 11编译器错误

我使用的是Visual C ++ 2010,这里是我的代码片段: std::set<int> s; decltype(s)::value_type param = 0; 我收到以下错误消息,任何人都可以帮助我? > error C2039: 'value_type' : is not a member of '`global namespace'' > error C2146: syntax error : missing ';' before identifier 'param' 这是去年在Connect上引发的Visual Studio错误。 它是问题757545(“范围运算符之前不能使用decltype”)。

Recursive trailing return type?

Possible Duplicate: trailing return type using decltype with a variadic template function I want to make a function that sums up several values. If I don't use a trailing return type then count() uses the type of the first argument as it's return type. However, when using a trailing return type I am not able to get the code to compile: #include <iostream> template<typenam

递归追溯返回类型?

可能重复: 尾随返回类型使用带有可变参数模板函数的decltype 我想创建一个总结多个值的函数。 如果我不使用尾随返回类型,则count()使用第一个参数的类型,因为它是返回类型。 但是,当使用尾随返回类型时,我无法获得编译的代码: #include <iostream> template<typename T> inline T sum(T a) { return a; } template<typename T, typename... Args> inline auto sum(T a, Args... b) -> decl