这个问题的答案如何使用clang ++/libc ++编译/链接Boost?陈述Boost与clang++和libc++,以下应该做:
./b2 clean
./b2 toolset=clang cxxflags="-stdlib=libc++" linkflags="-stdlib=libc++"
Run Code Online (Sandbox Code Playgroud)
我在Scientific Linux 6.4 x86_64主机上测试了上述提示,它"主要"用于构建完整的Boost 1_53_0发行版,使用clang++ 3.3sv和libc++ 3.3svn.我大多说,因为我真的想删除所有的libstdc++依赖.
不过,以下内容:
libboost_graphlibboost_localelibboost_regex仍显示libstdc++依赖关系(ldd输出使其非常明显).我想知道一个很好的方法来删除这样的,并会欣赏任何提示.
是实现定义还是标准建议流的默认填充字符?
示例代码:
#include <iostream>
#include <iomanip>
#include <sstream>
int main ()
{
std::stringstream stream;
stream << std::setw( 10 ) << 25 << std::endl;
std::cout << stream.str() << std::endl;
}
Run Code Online (Sandbox Code Playgroud)
同 clang++ --stdlib=libstdc++
$ clang++ --stdlib=libstdc++ test.cpp
$ ./a.out | hexdump
0000000 20 20 20 20 20 20 20 20 32 35 0a 0a
000000c
$
Run Code Online (Sandbox Code Playgroud)
同 clang++ --stdlib=libc++
$ clang++ --stdlib=libc++ test.cpp
$ ./a.out | hexdump
0000000 ff ff ff ff ff ff ff ff 32 35 0a 0a
000000c …Run Code Online (Sandbox Code Playgroud) 以下测试程序返回不同的结果,具体取决于我使用的是libc ++还是libstdc ++.
#include <sstream>
#include <iostream>
int main()
{
int a = 0;
void* optr = &a;
void* iptr;
std::stringstream ss;
ss << optr;
std::cout << ss.str() << '\n';
ss >> iptr;
std::cout << iptr << '\n';
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我在OSX 10.9.2上使用Xcode 5的以下版本的clang
$ xcrun clang++ --version
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
Run Code Online (Sandbox Code Playgroud)
这是使用libstdc ++和libc ++构建时的测试输出
$ xcrun clang++ test.cpp <-- libstdc++ version
$ ./a.out
0x7fff5ec723e8
0x7fff5ec723e8
$ xcrun clang++ test.cpp …Run Code Online (Sandbox Code Playgroud) 根据http://flamingdangerzone.com/cxx11/2012/07/06/optimal-tuple-i.html,关于std :: tuple ...
libstdc ++总是以相反的顺序放置成员,而libc ++总是按给定的顺序放置成员
假设这是真的,有没有理由(历史或其他)为什么libstdc ++使用逆序?
额外奖励:是否有任何实现因任何原因改变了其std :: tuple排序?
虽然libstdc ++没有,但libc ++确实遵循标准,该标准规定传递ios_base::failbit给basic_istream::exceptions格式化输入没有任何影响.例如这段代码:
istringstream is{"ASD"};
double foo;
is.exceptions(istream::failbit);
try {
is >> foo;
cout << foo << endl;
} catch(ios_base::failure& fail) {
cout << "ouch\n";
}
Run Code Online (Sandbox Code Playgroud)
会导致:
我对LWG2349的阅读是因为它basic_istream不会抛出任何格式化的输入.
例如,LWG2349建议对标准的27.7.2.3 [istream]/1进行更改,该标准引用了一个错误的失效,该错误会使libc ++行为像libstdc ++.更改以粗体显示,并在下面进行说明:
如果在输入期间抛出除抛出的异常
clear()(如果有的话)之外的异常,则ios::badbit在*this错误状态下打开.(抛出的异常如果basic_ios<>::clear()不会被捕获或重新抛出.)(exceptions()&badbit) != 0那么异常被重新抛出.
我明白这basic_istream::clear是对错误的格式化输入的反应,所以我误读了LWG2349还是实际上它会停止basic_istream抛出任何错误?
继承enable_shared_from_this只是为了能够shared_ptr从成员函数返回作为主要意图,而无意enable_shared_from_this在派生类中公开API.
因为要使用enable_shared_from_this一个必须通过公共继承这样做(标准是否要求这个?基本原理是什么?),这是无法实现的,并且enable_shared_from_thisAPI被强制导入到派生类的公共API中.
Inherenting enable_shared_from_this私下和制作shared_ptr的朋友千万级铛上加上的libc ++工作,但不与stdlibc ++工作.
由于private enable_shared_from_this+ friend shared_ptr(或受保护的继承)似乎涵盖了这个用例,因此适合作为"从此共享"问题的解决方案的标准不应该足够吗?
在查看std :: basic_string的libc ++实现时,我在第1374行(在撰写本文时)遇到了这个问题:
enum {__alignment = 16};
Run Code Online (Sandbox Code Playgroud)
此值用于后续对齐计算,字符串大小请求向上舍入为此数字的倍数.
我可以接受一些四舍五入是为了避免内存碎片或其他什么,但......
我想知道在这里使用硬编码16作为数字背后是否存在任何特定的理由,或者它是否只是用作"漂亮的'圆形'数字".
对于64位计算机来说,16相当于alignof( std::max_align_t ),这是有道理的.但完全相同的值__alignment也用于32位架构,所以......?
release()为了简单起见,libc++的shared_ptr实现可以描述为:
void release()
{
if (ref_count.fetch_sub(1, std::memory_order_acq_rel) == 1)
{
delete this;
}
}
Run Code Online (Sandbox Code Playgroud)
为什么libc++不把它分成release decrement和acquisition fence呢?
void release()
{
if (ref_count.fetch_sub(1, std::memory_order_release) == 1)
{
std::atomic_thread_fence(std::memory_order_acquire);
delete this;
}
}
Run Code Online (Sandbox Code Playgroud)
正如Boost 建议的那样,这看起来很优越,因为它不会对除最后一个减量之外的所有内容强加获取内存顺序。
尝试在Mac上使用pip install安装cvxpy软件包时,收到以下错误消息:
warning: include path for stdlibc++ headers not found; pass '-std=libc++' on the command line to use the libc++ standard library instead [-Wstdlibcxx-not-found]
In file included from cvxpy/cvxcore/src/cvxcore.cpp:15:
cvxpy/cvxcore/src/cvxcore.hpp:18:10: fatal error: 'vector' file not found
#include <vector>
^~~~~~~~
1 warning and 1 error generated.
error: command '/usr/bin/clang' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)
Mac正在运行OS Mojave.
我注意到在clang的libc ++中std::set::equal_range(与相同std::map)给出的结果与libstdc ++不同。我一直认为equal_range应该返回std::make_pair(set.lower_bound(key), set.upper_bound(key))cppreference和libstdc ++所做的等效。但是在libc ++中,我有一个给出不同结果的代码。
#include <set>
#include <iostream>
#include <iterator>
struct comparator {
using range_t = std::pair<int, int>;
using is_transparent = std::true_type;
bool operator()(int lhs, int rhs) const
{
return lhs < rhs;
}
bool operator()(int lhs, range_t rhs) const
{
return lhs < rhs.first;
}
bool operator()(range_t lhs, int rhs) const
{
return lhs.second < rhs;
}
};
using range_set = std::set<int, comparator>;
int main()
{
range_set set = …Run Code Online (Sandbox Code Playgroud)