![](/img/trans.png)
[英]How to use CMake to build a project with C++23 standard library module(import std)?
眾所周知,C++23 支持標准庫模塊。 直到 2023 年 5 月,MSVC 都支持它,但我們需要手動添加標准庫模塊,如Microsoft 博客所述。 但是如何在CMake項目中使用import std呢? 微軟博客沒有提到它。 而這些文件不能工作。( std.ifc文件取自微軟博客教程: cl ...
[英]How to use CMake to build a project with C++23 standard library module(import std)?
眾所周知,C++23 支持標准庫模塊。 直到 2023 年 5 月,MSVC 都支持它,但我們需要手動添加標准庫模塊,如Microsoft 博客所述。 但是如何在CMake項目中使用import std呢? 微軟博客沒有提到它。 而這些文件不能工作。( std.ifc文件取自微軟博客教程: cl ...
[英]is `return_if_null(T* ptr)` possible?
我發現自己做了很多void doSomethingCool(CoolObject* coolObject) { if (coolObject == nullptr) { return; } // now _actually_ do something cool } ...
[英]What is the use of a constexpr function in C++23?
關鍵字constexpr在將其引入 C++11 標准時對函數實施了非常嚴格的限制。 C++14 和 C++20(最值得注意的)放寬了這些限制: C++14 允許多個return語句、 static_assert等。 C++20 允許try和asm C++23 進一步放寬了這些限制。 從我在 ...
[英]Are floatN_t in stdfloat guarenteed to be IEEE compliant?
與基本類型( float 、 double和long double )不同,C++23 中引入的<stdfloat>中的新floatN_t類型是否始終是 IEEE 標准二進制浮點類型? cppreference for fixed width floating-point page確 ...
[英]C++23 std::views::zip errors when given a view of references to abstract base class
給定這個程序,用g++-13 -std=c++2b test.cpp : ……那是哪里……#include <array> #include <ranges> auto main() -> int { struct B { virtual void ...
[英]"atomic constraint depends on itself" error when compiling iterator in C++23
我正在嘗試制作一個迭代器,它主要逐個字符地傳遞字符串視圖,但有一些特殊情況,我嘗試的是以下內容:// iter.hpp #include <string_view> typedef std::basic_string_view<char> UStringView; cla ...
[英]Is std::print() thread safe, and does it have the interleaving of text problem?
std::print()將添加到 C++23中。 我想知道的是std::print()是否是線程安全的,在沒有數據競爭的意義上並且它是否有文本交錯問題,例如,如果我在線程 1 中有: 和線程 2: 它能以瘋狂的順序打印嗎,像這樣: 我想這兩個問題的答案都是肯定的,以與std::cout的行為相匹 ...
[英]How to use standard library macros with std module in C++23
我目前正在玩 C++ 模塊,試圖使我們公司的代碼 C++ 基礎現代化,以將模塊用於核心功能。 特別是即將推出的 C++23 std模塊,它作為預編譯頭文件的更好替代品似乎非常有趣。 所以我使用的是Visual Studio 2022 17.5 Preview 2.0,它初步支持std模塊。 順便說一 ...
[英]What is the rationale behind the iterator/sentinel of range adaptors providing the base() accessor?
遺留的迭代器適配器,如reverse_iterator和move_iterator ,或 C++20/23 新引入的適配器,如counted_iterator 、 basic_const_iterator和move_sentinel ,它們都提供base()成員以允許我們訪問底層迭代器/哨兵: 但 ...
[英]std::start_lifetime_as and UB in C++23 multithreaded application
假設X和Y是適合這種用法的類型,是否 UB 在一個線程的內存區域上使用std::start_lifetime_as<X>作為一種類型,並在另一個線程的完全相同的內存上使用std::start_lifetime_as<Y>線? 標准對此有任何說明嗎? 如果不是,正確的解釋是什 ...
[英]Mismatched argument pack lengths while expanding std::index_sequence and variadic argument pack
我一直在研究一個小型的多維張量數組實現; 並且遇到了std::make_index_sequence與可變參數模板參數結合的問題。 給出以下剝離的實現: 我現在想在調用運算符operator()()上有一個可變模板來訪問私有容器中的元素: 這個想法很簡單。 為張量的rank生成一個index_seq ...
[英]How to create a view that will split the data in half
我想創建一個視圖,該視圖將具有字符串兩半的視圖。 我添加了一些我想要實現的代碼示例。 我該怎么做?#include <iostream> #include <string> #include <ranges> #include <vector> #in ...
[英]error: 'to' is not a member of 'std::ranges'
面對問題std::ranges::to我正在執行來自https://en.cppreference.com/w/cpp/ranges/to的以下示例 但是得到一個錯誤 https://coliru.stacked-crooked.com/view?id=8fdd3554af82ef24 我正在使用 ...
[英]Coroutines: Do co_yielded string_views dangle?
我想混合 co_yielding 字符串文字和std::strings 但是,我想知道 std::string 的生命周期? 如果您知道您將立即使用string_view可能是安全的? https://godbolt.org/z/d5eoP9aTE 你可以像這樣讓它安全 ...
[英]Sorting two arrays using C++23 zip view
有一個相當典型的任務是同時對兩個 arrays 進行排序,假設 arrays 的相同索引元素形成虛擬對,這些元素已排序。 此類問題至少在 10 年前出現過: boost zip_iterator and std::sort 現在這個任務可以使用range-v3庫來解決: 在線演示: https:// ...
[英]What's the difference between C++23's optional::transform and optional::and_then?
C++23 添加了一些關於可選值的“monadic 風格”功能,作為optional<T>的方法: optional<T>::and_then() (並忽略this的限定符): 如果包含的值存在,則返回調用 f 的結果。 否則,返回返回類型的空值。optional< ...
[英]Can a union have a constexpr destructor if it has a member with non-trivial destructor?
看這個小例子: 這段代碼可以用 gcc 成功編譯,但是 clang 拒絕它( godbolt ): 哪個編譯器是正確的? 如果 clang 是正確的,有什么方法可以使u的定義在bar中合式(我可以對U做任何事情,但我必須保留Foo的非平凡 dtor)? 注意:我不想激活成員f ,我只想獲取ufy的 ...
[英]Somewhat inconsistent need for template disambiguator
在下面的示例中,我需要在標記為 #1 的行中使用template消歧器,而在其他出現的類似模式中似乎沒有必要。 它有什么不同?#include <cstdint> #include <utility> #include <array> #include <v ...
[英]C++ Vector values changing when dereferencing from another class
我需要從另一個 class 的 std::vector 構造一個 std::discrete_distribution。但是,我得到的一切都是錯誤的無法創建大於 max_size() 的 std::vector 我試圖將代碼簡化為基礎(也錯過了所有包含,因為其他一切都正常)。 此外,在花了很短的時 ...
[英]Is flat_map an STL container?
在當前的C++23s flat_map設計草案中,類型flat_map::reference被定義為pair<const key_type&, mapped_type&> ,即不是對flat_map::value_type = pair<key_type, map ...