是否有可能让Travis CI与能够使用C++ 11的Clang一起工作?(我想要Clang,而不是GCC,我已经在Travis CI中使用了GCC 4.8.)看来预安装的版本不支持C++ 11.我安装任何较新版本的所有尝试都因此失败:
In file included from /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/bits/move.h:57:
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/type_traits:269:39: error:
use of undeclared identifier '__float128'
struct __is_floating_point_helper<__float128>
Run Code Online (Sandbox Code Playgroud)
我见过这个-D__STRICT_ANSI__伎俩,但与我的其他事情发生了冲突.
是否有可能让它运作?另见我的.travis.yml.
POSIX和其他标准对多线程在同一时间执行poll()或select()调用单个套接字或管道句柄的情况有何看法?
如果有任何数据到达,只有一个等待线程被唤醒或所有等待线程被唤醒?
编辑:解决看到评论 - 不知道如何标记解决与答案.
在c ++ 0x中观看有关完美转发/移动语义的第9频道视频之后,我认为这是编写新分配运算符的好方法.
#include <string>
#include <vector>
#include <iostream>
struct my_type
{
my_type(std::string name_)
: name(name_)
{}
my_type(const my_type&)=default;
my_type(my_type&& other)
{
this->swap(other);
}
my_type &operator=(my_type other)
{
swap(other);
return *this;
}
void swap(my_type &other)
{
name.swap(other.name);
}
private:
std::string name;
void operator=(const my_type&)=delete;
void operator=(my_type&&)=delete;
};
int main()
{
my_type t("hello world");
my_type t1("foo bar");
t=t1;
t=std::move(t1);
}
Run Code Online (Sandbox Code Playgroud)
这应该允许将r值和const分配给它.通过使用适当的构造函数构造一个新对象,然后使用*this交换内容.这对我来说听起来很合理,因为没有数据被复制超过它需要的数量.指针算术很便宜.
但是我的编译器不同意.(g ++ 4.6)我得到了这些错误.
copyconsttest.cpp: In function ‘int main()’:
copyconsttest.cpp:40:4: error: ambiguous overload for ‘operator=’ in ‘t = …Run Code Online (Sandbox Code Playgroud) 我使用.NET的System.Management东西监视一些使用WMI的机器.我正在使用的查询是这样的:
SELECT Timestamp_Sys100NS, PercentProcessorTime
FROM Win32_PerfRawData_PerfOS_Processor
WHERE Name='_Total'
Run Code Online (Sandbox Code Playgroud)
从那里我使用众所周知的公式计算CPU使用率%:
double cpu_usage = (1 - (double)delta_cpu / delta_time) * 100;
Run Code Online (Sandbox Code Playgroud)
除了一台机器(目前为止),它的效果非常好.
问题是,对于一台机器,即Windows 2003服务器(启用超线程,如果重要),我有时会得到负CPU使用率值.换句话说,(double)delta_cpu / delta_time表达式产生数量> 1.我确实在网上搜索了为什么会发生这种情况,但我什么都没发现.
这个Windows 2003服务器是否具体?或者是超线程相关的问题?或者只是预期,我应该将CPU使用值或cpu_delta值限制在某个范围内?
编辑:
我用这台机器观察的第二个奇怪的事情是,该Timestamp_Sys100NS值并不表示FILETIME日期(自1600年1月1日以来的刻度),而是从启动时开始看起来像刻度.
编辑2:我现在已经验证了这个问题是在许多Windows 2003服务器上.而且我显然不是唯一一个有同样问题的人.
编辑3:我已经通过查询解决的时间邮票LastBootUpTime从Win32_OperatingSystem和补充说,到Timestamp_Sys100NS时的值Timestamp_Sys100NS是过去太远.这似乎给出了正确的日期和时间.从中检索日期之后操作日期的代码Win32_OperatingSystem如下所示:
WbemScripting.SWbemDateTime swbem_time = new WbemScripting.SWbemDateTime();
swbem_time.Value = date_str;
string time_as_file_time_str = swbem_time.GetFileTime(true);
return new DateTimeOffset(epoch.Ticks + long.Parse(time_as_file_time_str),
swbem_time.UTCSpecified
? TimeSpan.FromMinutes(swbem_time.UTC)
: TimeSpan.Zero); …Run Code Online (Sandbox Code Playgroud) 我正在编写侵入式共享指针,我正在使用C++ 11 <atomic>工具作为参考计数器.以下是我的代码的相关片段:
//...
mutable std::atomic<unsigned> count;
//...
void
SharedObject::addReference() const
{
std::atomic_fetch_add_explicit (&count, 1u,
std::memory_order_consume);
}
void
SharedObject::removeReference() const
{
bool destroy;
destroy = std::atomic_fetch_sub_explicit (&count, 1u,
std::memory_order_consume) == 1;
if (destroy)
delete this;
}
Run Code Online (Sandbox Code Playgroud)
我已经开始memory_order_acquire和memory_order_release第一次,但后来我说服自己memory_order_consume应该足够好.在进一步审议后,在我看来,即使memory_order_relaxed应该工作.
现在,问题是我是否可以memory_order_consume用于操作或者我可以使用较弱的订单(memory_order_relaxed)还是应该使用更严格的订购?
我在C++中遇到了隐式转换的问题.以下是一个最小的例子:
struct A {
virtual void f()=0; // abstract
};
struct Ad : A {
virtual void f() {} // not abstract
};
struct B {
operator Ad () const { return Ad(); }
};
void test(A const &lhs) {}
int main()
{
B b;
test(b);
}
Run Code Online (Sandbox Code Playgroud)
我希望编译器做的是:将b转换为Ad类型的变量(使用B中定义的转换)并将结果传递给test.但是,上面的代码不能在GCC中编译(启用C++ 11),结果是无法分配抽象类型"A"的对象.
有些事情需要注意:
f()=0;来使非抽象f() {},代码工作得很好.以下是否根据C++标准给出了定义的结果?
std::list<int> myList;
std::list<int>::iterator myIter = myList.begin(); // any issues?
myList.push_back( 123 );
myIter++; // will myIter point to the 123 I pushed?
Run Code Online (Sandbox Code Playgroud)
我可以在我正在使用的编译器上测试它...但我想要一个更明确的答案.
我在使用必须检查3个不同节点的模板时遇到问题,如果它们不是空的,则打印数据
我正在使用<xsl:if test="string-length(node) != 0">每个节点,然后进行输出,但它不打印任何东西.这就像测试返回零.
我已经选择了我想要检查长度的每个节点的父节点作为模板匹配,但它仍然不起作用.
另一件事,我如何使用排序列表<datefrom>.我试过使用这个,但是我收到了关于加载样式表的错误.如果我拿出它的工作方式
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template name="hoo" match="/">
<html>
<head>
<title>Registered Festival Organisers and Festivals</title>
<link rel="stylesheet" type="text/css" href="userfestival.css" />
</head>
<body>
<h1>Registered Festival Organisers and Festivals</h1>
<h3>Ordered by the festival date ascending</h3>
<xsl:apply-templates select="folktask/member"/>
<xsl:if test="position()=last()">
<div class="count"><h2>Total number of festival organisers: <xsl:value-of select="count(/folktask/member/user/account/userlevel[text()=3])"/></h2></div>
<div class="count"><h2>Total number of festivals: <xsl:value-of select="count(/folktask/member/festival)"/></h2></div>
</xsl:if>
</body>
</html>
</xsl:template>
<xsl:template match="folktask/member">
<xsl:if test="user/account/userlevel='3'">
<xsl:sort select="festival/event/datefrom"/>
<div class="userdiv">
<xsl:apply-templates select="user"/>
<xsl:apply-templates select="festival"/>
</div>
</xsl:if>
</xsl:template> …Run Code Online (Sandbox Code Playgroud) 如何通过图表api从facebook帐户获取关注者列表?
我从facebook帐户中得到了朋友
FB.api('/me/friends?access_token='+accessToken, {
fields : 'id, name, picture'
}, function(response) {
});
Run Code Online (Sandbox Code Playgroud)
有办法让我的Facebook帐户的粉丝?
当我在搜索有关我的源代码中的编译问题的线索时,我遇到了与函数查找相关的错误报告(针对Mozilla的JavaScript引擎源代码).引用错误报告:
TypedArrayTemplate(显然)是一个模板,它引用了静态内联函数INT_TO_JSVAL,没有用"::"作为前缀.这会破坏xlC,因为它无法解析INT_TO_JSVAL.如果在模板参数的上下文中找不到非限定名称,则标准不要求考虑静态.g ++做这个后备,xlC没有.
来自编译器的信息性消息:
(I) Static declarations are not considered for a function call if the function is not qualified.
Run Code Online (Sandbox Code Playgroud)
在我的情况下,失败的代码与此类似:
namespace N
{
static bool foo (std::string const &);
template <typename T>
void bar (T const &, std::string const & s)
{
// expected unqualified call to N::foo()
foo (s);
}
void baz (std::string const & s)
{
bar (s);
}
} // namespace N
Run Code Online (Sandbox Code Playgroud)
xlC实现的行为是否真的正确?2003或2011标准在哪里谈到这一点?