我想在其中使用nanoseconds类型定义,boost::posix_time但似乎未定义此类型。我查看了实现,看起来类型定义受
#if defined(BOOST_DATE_TIME_HAS_NANOSECONDS)
Run Code Online (Sandbox Code Playgroud)
所以我加了我的代码
# define BOOST_DATE_TIME_HAS_NANOSECONDS
Run Code Online (Sandbox Code Playgroud)
但我不断收到相同的编译错误。我在网络上的某些页面上看到可能需要重建boost库,这对我来说非常好,但是我没有在bootstrap.sh或中看到任何相关标志b2,即使这是我希望在运行期间出现此问题的问题链接不编译。任何想法是什么问题?提前致谢。
在我附加的代码中,我正在寻找一种方法将1种类型映射到另一种类型.代码无法使用错误进行编译
[root@]# g++ -std=c++11 test.cpp -o test; ./test
test.cpp: In member function ‘void A::Func(AType)’:
test.cpp:32:58: error: template argument 1 is invalid
using BType = std::result_of<GetBTypeFromAType(AType)>::type;
Run Code Online (Sandbox Code Playgroud)
我正在使用的编译器版本是5.3.1,任何想法如何解决?
#include <iostream>
#include <typeinfo>
#include <cxxabi.h>
#include <memory>
template <class T>
std::string GetTypeName()
{
//http://stackoverflow.com/questions/23266391/find-out-the-type-of-auto/23266701#23266701
std::unique_ptr<char, void(*)(void*)> name{abi::__cxa_demangle(typeid(T).name(), 0, 0, nullptr), std::free};
return name.get();
}
struct A
{
struct AA {};
struct AB {};
struct AC {};
struct BA {};
struct BB {};
struct BC {};
BA GetBTypeFromAType(AA a) { return BA(); }
BB …Run Code Online (Sandbox Code Playgroud) 这是我要使用的宏,如果X_DEFINED已定义,它将被评估为DEFAULT_X,否则将被评估为x
#define GET_X(x) (defined(X_DEFINED) ? DEFAULT_X : x)
Run Code Online (Sandbox Code Playgroud)
它无法编译,并显示错误
error: 'X_DEFINED' was not declared in this scope
Run Code Online (Sandbox Code Playgroud)
有什么建议么?我希望能够根据是否X_DEFINED已定义在参数和全局变量之间进行选择
unique_ptr( pointer p, /* see below */ d1 ) noexcept;
(3)
unique_ptr( pointer p, /* see below */ d2 ) noexcept;
(4)
Run Code Online (Sandbox Code Playgroud)
这里有 2 个构造函数,Deleter 案例的描述是非参考的
a) If D is non-reference type A, then the signatures are:
unique_ptr(pointer p, const A& d) noexcept;
(1) (requires that Deleter is nothrow-CopyConstructible)
unique_ptr(pointer p, A&& d) noexcept;
(2) (requires that Deleter is nothrow-MoveConstructible)
Run Code Online (Sandbox Code Playgroud)
我检查了 gcc 和 llvm 代码,但我没有看到nothrow强制要求。构造函数 3-4 被标记,noexcept因此Deleter在调用其构造函数时不应抛出是有道理的。但我不确定为什么在他们提供的示例中,构造函数没有标记为noexcept.
struct D { // …Run Code Online (Sandbox Code Playgroud) 我有这个代码
#include <iostream>
size_t F()
{
return 0;
}
template <class Type, class... NextTypes>
size_t F(const Type& type, const NextTypes&... nextTypes)
{
if (!std::is_const<Type>::value)
return sizeof(type) + F(nextTypes...);
else
return F(nextTypes...);
}
int main()
{
int a = 0;
const int b = 0;
const size_t size = F(a,b);
std::cout << "size = " << size << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我试图在编译时知道常量参数和非常量参数的总大小.当前输出为8,由于某种原因,编译器认为b不是常量,我使用typeid并decltype打印类型a和b输出显示确实b是一个int而不是const int我预期的.我错过了什么?是否有可能将一组可变参数分别为const参数和非const?
在Windows中的几乎所有基本编辑器中,我可以选择几行代码并来回缩进它们,是否有一种简单的方法可以在vim中完成它?