pat*_*t0h 5 c++ boost wrapper cstdint
Boost的C99 stdint实现非常方便.但有一件事让我感到困惑.他们将所有的typedef转储到boost namespace.这使我在使用此工具时有三个选择:
using namespace boost"using boost::[u]<type><width>_t"boost::前缀明确引用目标类型; 例如,boost::uint32_t foo = 0;boost::前缀常常≥所讨论的类型的长度.我的问题是:将所有这些类型引入全局命名空间的最优雅方法是什么?我应该只boost/cstdint.hpp使用选项№2 写一个包装器并用它完成吗?
此外,像这样包装标题在VC++ 10上不起作用(标准库标题的问题):
namespace Foo
{
#include <boost/cstdint.hpp>
namespace boost_alias = boost;
}
using namespace Foo::boost_alias;
Run Code Online (Sandbox Code Playgroud)
编辑:我想另一个选择是使用预处理器使其在VC 10上工作?以上片段为例:
#ifndef FOO_HPP_INCLUDED
#define FOO_HPP_INCLUDED
#if _MSC_VER >= 1600 /*VC++ 10*/ || defined USE_NATIVE_STDINT_HEADER
#include <stdint.h>
#else
namespace cstdint_wrapper
{
#include <boost/cstdint.hpp>
namespace boost_alias = boost;
}
using namespace cstdint_wrapper::boost_alias;
#endif
#endif
Run Code Online (Sandbox Code Playgroud)
我觉得工作少了?
我只是使用C99 stdint.h(现在实际上是在VS 2010中).对于不包含它的Visual C/C++版本,我使用MinGW的公共域版本,我修改后使用VC6(从我必须在VC6中工作时):
在这个SO问题中你可能会考虑其他几个选项:C99 stdint.h header和MS Visual Studio
如果你想继续使用boost/cstdint.hpp,我会说实现一个将类型带入全局命名空间的包装器头的建议是可行的方法.
是否boost/cstdint.hpp提供了我不应该知道的任何内容stdint.h?