从range-v3的文档中:
view::all返回包含源中所有元素的范围.用于将容器转换为范围.
让我困惑的是:
view::all使用?std::vector,std::list等)在概念上不是范围吗?例如:
auto coll = std::vector{ 1, 2, 2, 3 };
view::all(coll) | view::unique; // version 1
coll | view::unique; // version 2
Run Code Online (Sandbox Code Playgroud)
有什么区别version 1和version 2?
我正在尝试在带有 ndk r17 的 android 项目中使用实验性文件系统,并且我正在使用 STL c++_static 但我得到了这个:
undefined reference to `std::experimental::filesystem::v1::__current_path(std::__ndk1::error_code*)'
Run Code Online (Sandbox Code Playgroud)
我展示了一些建议将 -lstdc++fs 添加到链接器参数的主题,但链接器找不到这个库
当前的 ndk 是否支持此实验性功能?
我刚刚遇到好奇的std :: experimental :: propagate_const错误.以下代码段演示了此问题
#include <memory>
#include <experimental/propagate_const>
#include <map>
class FWD;
//compiles
class A
{
std::unique_ptr<FWD> m;
};
//compiles
class B
{
std::experimental::propagate_const<std::unique_ptr<FWD>> m;
};
//compiles
class C
{
std::unique_ptr<std::map<int, FWD>> m;
};
//does not compile!
class D
{
std::experimental::propagate_const<std::unique_ptr<std::map<int, FWD>>> m;
};
Run Code Online (Sandbox Code Playgroud)
所以你不能只用传播的unique_ptr替换unique_ptr,因为有时你的前向声明会破坏它.
如果有人向我解释为什么编译在当前的propagate_const实现中失败,我将不胜感激.它与某些事情有关
typedef remove_reference_t<decltype(*std::declval<_Tp&>())> element_type;
Run Code Online (Sandbox Code Playgroud)
因为解决方法是:
template <typename T, typename = void>
struct get_element_type
{
using type = std::remove_reference_t<decltype(*std::declval<T&>())>;
};
template <typename T>
struct get_element_type<T, typename std::enable_if<!std::is_void<typename T::element_type>::value>::type>
{
using type = typename T::element_type; …Run Code Online (Sandbox Code Playgroud) 我试图做github std::simd上给出的例子,但我的矢量化版本最终慢了 2-3 倍。如何正确使用?
该纪录片缺乏严肃的文档和进一步的示例用法。没有列出构造函数等。我确定我可能以错误的方式使用它,但是由于文档有限,我不知道如何继续。
g++ -o test test.cpp --std=c++2a -O0
#include <array>
#include <chrono>
#include <cstdlib>
#include <experimental/simd>
#include <iostream>
#include <random>
using std::experimental::native_simd;
using Vec3D_v = std::array<native_simd<float>, 3>;
native_simd<float> scalar_product(const Vec3D_v& a, const Vec3D_v& b) {
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
}
using Vec3D = std::array<float, 3>;
float scalar_product(const std::array<float, 3>& a, const std::array<float, 3>& b) {
return a[0] * b[0] + a[1] * b[1] + a[2] …Run Code Online (Sandbox Code Playgroud) 我几乎可以肯定,如果没有反思,我正在寻找的东西就无法完成,而反思还没有出现在语言中。但有时我会对 SO 中的特殊答案感到惊讶,所以让我们尝试一下。
\n是否可以推导出具有共同共享基类的两种类型的“common_base”,因此以下内容是可能的(伪代码! -语言中没有 ,这就是我想要实现的魔力) :common_base_t
template<typename T1, typename T2>\nconst common_base_t<T1, T2>& foo(const T1& a1, const T2& a2) {\n if(a1 < a2) return a1;\n return a2;\n}\nRun Code Online (Sandbox Code Playgroud)\n请注意,上面a1的 和a2并不共享 a common_type,只是作为兄弟(共享相同的基数),因此我们不能使用三元运算符。
另请注意,将上述返回类型更改为 并const auto&不能解决问题(它不会编译:auto return type 的推导不一致)。
这是 na\xc3\xafve 实现,要求调用者声明预期的返回类型:
\ntemplate<typename R>\nconst R& foo(const auto& a1, const auto& a2) {\n if(a1 < a2) return a1;\n return a2;\n}\nRun Code Online (Sandbox Code Playgroud)\n然后我们可以这样调用它: …
我最近听说了新的c ++标准功能,这些功能包括:
我无法弄清楚它们在哪些情况下比另一种情况更适用和有用。
std::experimental::source_location可能会在某些时候添加到C++标准中.我想知道是否有可能将位置信息放入编译时领域.本质上,我想要一个从不同的源位置调用时返回不同类型的函数.像这样的东西,虽然它没有编译,因为location对象不是constexpr因为它是一个函数参数:
#include <experimental/source_location>
using namespace std::experimental;
constexpr auto line (const source_location& location = source_location::current())
{
return std::integral_constant<int, location.line()>{};
}
int main()
{
constexpr auto ll = line();
std::cout << ll.value << '\n';
}
Run Code Online (Sandbox Code Playgroud)
这不会编译,有关于的消息
expansion of [...] is not a constant expression
Run Code Online (Sandbox Code Playgroud)
关于这return std::integral_constant<int, location.line()>{}条线.有什么好处它是有方法source_location是constexpr,如果我不能使用它们?
c++ templates compile-time c++-experimental std-source-location
令人兴奋的 的存储库mdspan是为 C++ 标准库建议的多维类似物std::span,现在还包含密切相关的 的参考实现mdarray,与mdspan拥有其数据不同。
但是,尽管该submdspan函数可以生成 的子集mdspan,但我找不到 的类似物mdarray。submdspan我期待的是一个行为与返回完全相同的函数mdspan,但它对 进行操作mdarray。
这是有计划但尚未实施吗?如果没有,为什么不呢?
编辑:
我已经用自制解决方案暂时解决了这个问题,其形式是重载submdspan,mdarray然后创建一个映射mdspan到整个 的临时文件mdarray,并调用submdspan它。
现在它可以完成工作了!但我不确定这是否涵盖了所有可能的情况mdarray,因为目前几乎没有文档。仍然希望得到原来问题的答案。
template <class ElementType, class Extents, class LayoutPolicy, class... SliceSpecs>
auto submdspan(
mdarray<ElementType, Extents, LayoutPolicy> &arr,
SliceSpecs... slices)
{
return submdspan(
mdspan<ElementType, Extents, LayoutPolicy>(arr.data(), arr.mapping()),
slices...);
}
Run Code Online (Sandbox Code Playgroud) 我很高兴看到std::experimental::filesystemVisual Studio 2017中增加了对它的支持,但刚才遇到了Unicode问题。我有点盲目地假设我可以在任何地方使用UTF-8字符串,但是失败了- 将a 构造为std::experimental::filesystem::path从a char*到UTF-8编码的字符串时,不会发生任何转换(即使标头在内部使用_To_wide和_To_byte起作用。我也写了一个简单的测试示例:
#include <string>
#include <experimental\filesystem>
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
static inline std::string FromUtf16(const wchar_t* pUtf16String)
{
int nUtf16StringLength = static_cast<int>(wcslen(pUtf16String));
int nUtf8StringLength = ::WideCharToMultiByte(CP_UTF8, 0, pUtf16String, nUtf16StringLength, NULL, 0, NULL, NULL);
std::string sUtf8String(nUtf8StringLength, '\0');
nUtf8StringLength = ::WideCharToMultiByte(CP_UTF8, 0, pUtf16String, nUtf16StringLength, const_cast<char *>(sUtf8String.c_str()), nUtf8StringLength, NULL, NULL);
return sUtf8String;
}
static inline std::string FromUtf16(const std::wstring& sUtf16String)
{
return FromUtf16(sUtf16String.c_str());
}
static inline std::wstring ToUtf16(const char* pUtf8String)
{
int …Run Code Online (Sandbox Code Playgroud) c++ ×9
std ×2
android ×1
android-ndk ×1
c++17 ×1
compile-time ×1
mdspan ×1
range-v3 ×1
standards ×1
templates ×1
type-traits ×1
unicode ×1
utf-8 ×1
visual-c++ ×1