我正在使用可变参数模板(gcc 4.5)并遇到这个问题:
template <typename... Args>
boost::tuple<Args...>
my_make_tuple(Args... args)
{
return boost::tuple<Args...>(args...);
}
int main (void)
{
boost::tuple<int, char> t = my_make_tuple(8, 'c');
}
Run Code Online (Sandbox Code Playgroud)
GCC错误消息:
sorry, unimplemented: cannot expand 'Arg ...' into a fixed-length argument list
In function 'int my_make_tuple(Arg ...)'
Run Code Online (Sandbox Code Playgroud)
如果我更换的每次出现boost::tuple的std::tuple,它编译罚款.
boost元组实现有问题吗?或者这是一个gcc bug?
我现在必须坚持使用Boost.Tuple.你知道任何解决方法吗?
谢谢.
我想使用Label of字段而不是名称来更新QC中的自定义用户字段
目前我们这样做
Set currentRun = QCUtil.CurrentRun
currentRun.Field("RN_USER_03") = 1
currentRun.Post
Run Code Online (Sandbox Code Playgroud)
但我想这样做
Set currentRun = QCUtil.CurrentRun
currentRun.Field("Data Rows Passed") = 4
currentRun.Post
Run Code Online (Sandbox Code Playgroud)
但我找不到这样做的方法.有任何想法吗?
为了使用Visual Studio 10编译以下程序,我得到了很多编译错误:
#include "stdafx.h"
#include <tuple>
#include <string>
#include <map>
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
typedef std::tuple<std::string, std::string> key_t;
typedef std::map<key_t, std::string> map_t;
map_t the_map;
auto k = std::make_tuple("one", "two");
the_map[k] = "the value";
auto q = std::make_tuple("one", "two");
auto i = the_map.find(q);
std::cout << i->second << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
错误1错误C2664:'std :: basic_string <_Elem,_Traits,_Ax> :: basic_string(const std :: basic_string <_Elem,_Traits,_Ax>&)':无法将参数1从'const key_t'转换为'const std :: basic_string <_Elem,_Traits,_Ax>&'c:\ program files(x86)\ microsoft visual studio 10.0\vc\include\tuple 127 1 tuple
来自这条线: …
我有两个类int_t,uint_t有符号类型和无符号类型:
template <typename lo_t> struct uint_t;
template <typename hi_t, typename lo_t>
struct int_t
{
lo_t lo;
hi_t hi;
int_t() : hi(0), lo(0) {}
int_t(int value) : lo(value), hi(value<0? -1: 0) {}
int_t(unsigned value) : lo(value), hi(0) {}
int_t(const uint_t<lo_t>&);
//template<typename ty_a, typename ty_b> int_t(const int_t<ty_a, ty_b>&);
};
template <typename hi_lo>
struct uint_t
{
hi_lo lo, hi;
uint_t() : lo(0), hi(0) {}
uint_t(int value) : lo(value), hi(value<0? -1: 0) {}
uint_t(unsigned value) : lo(value), hi(0) {}
template<typename …Run Code Online (Sandbox Code Playgroud) 我是C++的新手.
我有一个类,我想在类的函数中创建一个线程.并且该线程(函数)也将调用并访问类函数和变量.一开始我尝试使用Pthread,但只在类外工作,如果我想访问类函数/变量,我得到了一个超出范围的错误.我看一下Boost/thread但是不可取,因为我不想在我的文件中添加任何其他库(出于其他原因).
我做了一些研究,找不到任何有用的答案.请举一些例子来指导我.非常感谢!
尝试使用pthread(但我不知道如何处理我上面提到的情况):
#include <pthread.h>
void* print(void* data)
{
std::cout << *((std::string*)data) << "\n";
return NULL; // We could return data here if we wanted to
}
int main()
{
std::string message = "Hello, pthreads!";
pthread_t threadHandle;
pthread_create(&threadHandle, NULL, &print, &message);
// Wait for the thread to finish, then exit
pthread_join(threadHandle, NULL);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 在打字稿,你可以索引到一个对象只使用string,number或symbol。
我想有一个泛型,允许将泛型参数用作索引。
function foo<T extends number|string>(a: T): void {
let x: any = {};
x[a] = 42; // Error: an index expression argument must be of type...
}
Run Code Online (Sandbox Code Playgroud)
如果我强制转换为number|string,它将编译为:
function foo<T extends number|string>(a: T): void {
let x: any = {};
let i: number|string = a;
x[i] = 42; // OK
}
Run Code Online (Sandbox Code Playgroud)
因此,类型检查器足够聪明,可以知道如果可以T扩展,number|string则可以将其分配给一个number|string(然后可以用来将其索引到一个对象中),但是由于某种原因,它不允许我T直接使用a进行索引。
有没有一种方法可以在通用约束中指定所传递的类型可以用作索引器?
注意:我使用的是泛型而不是number|string直接使用,因为我想将泛型限制为仅接受来自特定字符串enum或字符串常量联合的值。
编辑: …
我正在尝试理解typescript 2.8 中的新条件类型。
例如,我有一些具有数组属性的对象,这些对象在我的流程中必须恰好有一个元素,并且我想获取该值。这是我认为应该有效的代码,它正确地只允许传入相关属性,但我不知道如何指定返回类型。我收到以下编译错误:
Type
number不能用于索引 typePick<T, { [K in keyof T]: T[K] extends any[] ? K : never; }[keyof T]>[K]。
n并且and的类型s被推导为 benumber|string而不是numberforn和stringfor s。
代码如下:
type ArrayProperties<T> = Pick<T, {
[K in keyof T]: T[K] extends Array<any>? K : never
}[keyof T]>;
const obj = {
a: 4,
n: [2],
s: ["plonk"]
};
// Compilation error on next line
function single<T, K …Run Code Online (Sandbox Code Playgroud) 我刚刚意识到我引入的一个错误,令我感到惊讶的是它编译了,打开常量是否合法?
Visual Studio 8和Comeau都接受它(没有警告).
switch(42) { // simplified version, this wasn't a literal in real life
case 1:
std::cout << "This is of course, imposible" << std::endl;
}
Run Code Online (Sandbox Code Playgroud) 我有一个这样的界面:
typedef struct Tree {
int a;
void* (*Something)(struct Tree* pTree, int size);
};
Run Code Online (Sandbox Code Playgroud)
然后据我所知,我需要创建它的实例,并使用Something方法将值设置为'size'.所以我这样做
struct Tree *iTree = malloc(sizeof(struct Tree));
iTree->Something(iTree, 128);
Run Code Online (Sandbox Code Playgroud)
但它始终无法初始化.我这样做了吗?如果Something方法的第一个成员是指向同一个结构的指针?
有人可以解释一下吗?
谢谢
以下是weak_ptr的构造函数中的两个:http: //msdn.microsoft.com/en-us/library/bb982126.aspx
weak_ptr(const weak_ptr&);
template<class Other>
weak_ptr(const weak_ptr<Other>&);
Run Code Online (Sandbox Code Playgroud)
实际代码(来自memory):
weak_ptr(const weak_ptr& _Other)
{ // construct weak_ptr object for resource pointed to by _Other
this->_Resetw(_Other);
}
template<class _Ty2>
weak_ptr(const weak_ptr<_Ty2>& _Other,
typename enable_if<is_convertible<_Ty2 *, _Ty *>::value,
void *>::type * = 0)
{ // construct weak_ptr object for resource pointed to by _Other
this->_Resetw(_Other);
}
Run Code Online (Sandbox Code Playgroud)
Q1:为什么顶级拷贝构造函数就在那里?它看起来像每个案例的底部(包括前一个).它甚至被调用了吗?如果它们没有包含它,那么底部的它会占据它的位置吗?
Q2:底层(模板化)构造函数的第二个参数发生了什么.我想我理解SFINAE方面,但我不明白为什么有一个额外的*之后::type