问题标签 [libc++]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
1962 浏览

c++ - C++11 和 [17.5.2.1.3] 位掩码类型

该标准允许人们在整数类型、anenum和 a之间进行选择std::bitset

考虑到这些选择,为什么库实现者会使用其中一个?

例如,llvm 的 libcxx 似乎使用了(至少)以下两个实现选项的组合:

ctype_base::mask使用整数类型实现: <__locale>

regex_constants::syntax_option_type使用enum+ 重载运算符实现: <regex>

gcc 项目的 libstdc++ 使用所有三个

ios_base::fmtflags使用枚举 + 重载运算符实现:<bits/ios_base.h>

regex_constants::syntax_option_type使用整数类型 regex_constants::match_flag_type实现,使用std::bitset
Both 实现:<bits/regex_constants.h>

AFAIK,gdb 无法“检测”这三个选项中任何一个的位域,因此增强调试不会有区别。

enum解决方案和整数类型解决方案应始终使用相同的空间。std::bitset似乎没有做出保证,sizeof(std::bitset<32>) == std::uint32_t所以我看不出有什么特别吸引人的地方std::bitset

enum解决方案似乎不太安全,因为掩码的组合不会生成枚举器。

严格来说,上述内容是关于n3376而不是 FDIS(因为我无权访问 FDIS)。

在这方面的任何可用启示将不胜感激。

0 投票
7 回答
67370 浏览

c++ - 类型不完整的 std::unique_ptr 不会编译

我正在使用 pimpl-idiom std::unique_ptr

但是,我在第 304 行中收到关于使用不完整类型的编译错误<memory>

sizeof' ' 对不完整类型 ' uixx::window::window_impl'的无效应用

据我所知,std::unique_ptr应该可以与不完整的类型一起使用。这是 libc++ 中的错误还是我在这里做错了什么?

0 投票
2 回答
1726 浏览

templates - 在 typedef 中实例化具有不完整类型的列表

我在编译 llvm 时遇到问题。问题是我当前的编译器(clang + libc++)试图在模板参数被定义之前实例化一个模板。这是代码示例:

编译器的错误是这样的:

据我所知,编译器会尝试实例化std::list<NodeEntry>以获取迭代器。这失败了,因为尚未定义 NodeEntry。当然,EdgeEntry 正在使用 NodeEntry,反之亦然。

显而易见的问题是:我该如何解决?
教育问题是:为什么编译器在定义类型时尝试实例化模板?它不应该等到我们对列表做点什么吗?

谢谢。

0 投票
2 回答
1474 浏览

debugging - 在 Xcode 4.3.1 中使用 libc++ 时如何获得合理的变量显示?

我使用 Xcode 4.3.1 的 C++11 语言方言以及 libc++ 作为标准库。这种组合中的语言支持令人惊叹,但调试却是一种折磨。Xcode 的“摘要格式”和 lldb 的摘要格式功能都不会以漂亮的打印显示任何标准类型(std::string、std::vector 等)。由于它们的复杂性,为这些类型编写漂亮的打印机非常重要。(例如,std::string 在 libc++ 中非常复杂。)

在这种情况下,其他开发人员如何获得适合 STL 类型的变量显示?还是没有其他人使用带有 Xcode/lldb 的 libc++?

0 投票
1 回答
1381 浏览

macos - 与 libc++ 编译的 boost 链接

我仍在为 libc++ 和 boost 苦苦挣扎。

我在这里用 libc++ 编译了 boost: 如何用 clang++/libc++ 编译/链接 Boost?

现在我在我的一台机器上看到了这个编译错误,而另一台机器用确切的代码编译得很好。它们都具有相同的编译器版本,环境变量也相同。

这是错误:

我仍然遇到 ABI 不兼容问题?

这是代码:

代码编译得很好,但只有在链接时出错。这是编译的额外信息:

另一方面,在编译良好的机器上,我可以从字面上“看到”libc++ 的速度。在 Xcode 中使用时,它非常快,并且使用 libc++ 完成代码非常棒。

但在我进一步享受之前,我真的很想深入了解这个......

0 投票
2 回答
5486 浏览

c++ - 在 std::unordered_map 中使用对象引用作为键

我想知道是否可以在 C++ 的 unordered_map 容器中使用对象引用作为键。

在尝试编译这个简单的代码片段时,我遇到了一些关于方法重新定义的错误:

在 libc++ 中使用 clang

/usr/include/c++/v1/unordered_map:352:12:错误:无法重新声明类成员

size_t operator()(const _Cp& __x) const

将 gcc 4.6 与 libstdc++ 一起使用

/usr/include/c++/4.6/bits/hashtable_policy.h:556:5:错误:'std::__detail::_Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>::mapped_type& std ::__detail::_Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>::operator [with _Key = Object&, _Pair = std::pair, _Hashtable = std::_Hashtable, std::allocator >, std::_Select1st >, std::equal_to, object_hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, false, false, true>, std::__detail ::_Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>::mapped_type = int]'不能重载

/usr/include/c++/4.6/bits/hashtable_policy.h:537:5 : 错误: with 'std::__detail::_Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>::mapped_type& std::__detail::_Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>::operator[](const _Key&) [with _Key = Object&, _Pair = std::pair, _Hashtable = std: :_Hashtable, std::allocator >, std::_Select1st >, std::equal_to, object_hash, std::__detail::_Mod_range_hashing, std::__detail::_Default_ranged_hash, std::__detail::_Prime_rehash_policy, false, false, true>, std::__detail::_Map_base<_Key, _Pair, std::_Select1st<_Pair>, true, _Hashtable>::mapped_type = int]'</p>

如果我改用旧的 gnu hash_map (__gnu_cxx::hash_map),我就没有这个问题。

这是新标准施加的一些限制吗?如果是,为什么?

有没有办法解决这个限制?

0 投票
1 回答
972 浏览

c++ - Clang++ 非静态数据成员初始化错误?C++11

我似乎无法弄清楚 Clang 在说什么,或者它是否正确,因为 G++-4.7 似乎可以很好地编译它。

该错误来自尝试std::uniform_int_distribution使用大括号为非静态成员初始化。

以下失败(token_count是模板参数): std::uniform_int_distribution<Int> random_dist{0, token_count-1};

出现错误:

但是,我可以通过这样做来初始化它:

std::uniform_int_distribution<Int> random_dist = std::uniform_int_distribution<Int>(0, token_count - 1);

我正在使用以下命令来编译它:clang++ -std=c++11 -stdlib=libc++ -lc++abi使用 Clang-3.2。

输出clang -v

0 投票
2 回答
850 浏览

c++ - 带有 unordered_map 的模板代码膨胀

我想知道是否unordered_map使用类型擦除来实现,因为unordered_map<Key, A*>andunordered_map<Key, B*>可以使用完全相同的代码(除了强制转换,这是机器代码中的无操作)。也就是说,两者的实现都可以基于unordered_map<Key, void*>节省代码大小。

更新:这种技术通常被称为瘦模板习语(感谢下面的评论者指出这一点)。

更新 2:我会对Howard Hinnant的意见特别感兴趣。让我们希望他能读到这篇文章。

所以我写了这个小测试:

并使用各种设置确定编译输出的大小:

事实证明,在我尝试的所有设置中,很多内部代码unordered_map似乎被实例化了两次:

(使用 Apple Xcode 的编译器)

现在的问题是:是否有一些令人信服的技术原因导致实施者选择省略这个简单的优化?

另外:为什么地狱的效果-Os与宣传的完全相反?

更新 3

正如 Nicol Bolas 所建议的那样,我使用shared_ptr<void/A/B>而不是裸指针(使用创建make_shared和投射static_pointer_cast)重复了测量。结果的趋势是相同的:

0 投票
0 回答
105 浏览

c++ - libc++ 中的 std::function 回调

可能重复:
std::function 的复制构造函数是否要求模板类型的参数类型是完整类型?

我有一个简单的类,它在 std::function 上构建了一个回调,但它不是用 C++11/libc++ 构建的。我想我看到了错误,但我不知道解决方案。

完整的错误日志:

因此, std::function 并不完整。但我希望这个类能够引用一个回调,这个类。所以我有点苦恼。有人知道如何用 C++11 处理这个问题吗?

注意:此代码在使用时编译没有问题<tr1/functional>

0 投票
2 回答
4007 浏览

c++ - clang libc++ error: overload resolution selected implicitly-deleted copy assignment operator

I can't get a C++11 project using clang 3.1 to compile. The command to the compiler is this:

And the error I get, since I included the "-stdlib=libc++" directive, is this:

Can anyone advise me on how I can get this to work?

The file I'm trying to compile doesn't even have to include any C++11 code for this error to occur, the "-stdlib=libc++" directive alone is enough to make it break.

Thanks for any & all assistance, Doug.

UPDATE: Hi -- the code is pretty basic, but in making it as basic as possible, I came across this error:

To get this error, I stripped my code back to this:

Which makes this look like something pretty fundamentally wrong.

I don't get this error when I take out the "-stdlib=libc++" directive to the compiler.