C + + dynamic news push issue 45
article
The highlights of various proposals for 2023 are introduced
As I said before, for example Deducing this For example, multidimensional array operator, auto instead of decay_copy, 123uz suffix stack_trace library, enhanced optional, move_ only_ Function (function_ref), fine support for string, resize_and_overwrite
- Almost Always Unsigned Use un signed as much as possible for various index es. After all, the overflow problem is too serious
- Named parameters for C++11 with variadic templates vs a language feature
Let's have a python explanation
parser.add_argument( '-f', metavar='FILE', type=argparse.FileType('r'), default=sys.stdin, dest='file', help='path to file containing the csv benchmark data')
How can this use of field name = value be implemented in c + +?
Obscene method, c
struct Named { int size; int defaultValue; bool forced; bool verbose; Named() : size(0), defaultValue(0), forced(false), verbose(false) {}; }; void foo(Named); void bar() { foo({ .size = 44, .forced = true}); }
But we want this
void bar() { foo(size: 44, forced: true); }
I can only say that there is a proposal D2288R0 Proposal of Designated Arguments DRAFT 2 If you can use it, it's really cool, especially the constructor, with clearer semantics
This specification can also solve the problem introduced by the order of the default parameters of the constructor, such as f(int a=1,b=1,c=1,d=1,e=1). I want to specify the two values of b/d. at present, I can only supplement the previous ac, which is very uncomfortable
The changes of c + + functions in recent years, such as various keyword modifications, are discussed
template <typename T> T add(T a, T b) { return a + b; } template <> int add<int>(int a, int b) = delete; int main() { add(1, 2); // error, this specialization is deleted }
Return value derivation
template <typename T, typename U> auto add(T a, U b) { return a + b; }
And the latest consteval, concept restrictions, etc
auto add(std::integral auto a, std::integral auto b) { return a + b; }
Even virtual functions can be consteval
struct magic { constexpr virtual int def() const { return 0; } }; struct programming_magic : public magic { constexpr int def() const override { return 42; } }; constexpr int initval(magic const & m) { return m.def() + 1; } int main() { constexpr programming_magic pm; int arr[initval(pm)] = {0}; }
And the latest collaboration
#include <cppcoro/task.hpp> cppcoro::task<> consume_items(int const n) { int i = 1; for(auto const& s : produce_items()) { print_time(); std::cout << "consumed " << s << '\n'; if (++i > n) break; } co_return; }
I didn't understand what the bug was
The 32-bit timestamp is no longer available
December 31, 2021 at 23:59 is represented as 2112359 32-bit (maximum is 2147483647)
January 1, 2022 at 00:00 indicates that 220101000 has overflowed
TODO: I don't understand, brothers
video
There may be conflicts with third-party implementations. So don't open the namespace
project
- asteria A script language that can be embedded. I hope fat friends can help me for a long time. I can also add a group of 128705139 to match the line with the author
- pika A nosql store, redis over rocksdb, is in great need of code contribution. Fat friends, interested, welcome to join the group 294254078 to check the line
- Taskflow v3.3 released! This library is very awesome
- fmt Update version 8.1, and the printing related to chrone is faster and ten times higher. Use friends to upgrade as much as possible
- CXXIter: A chainable c++20 LINQ-like iterator library
Another linq library, the author believes that range is still difficult to use
Several use examples
std::vector<int> input1 = {1337, 42, 128}; std::vector<std::string> input2 = {"1337", "42", "128"}; std::unordered_map<int, std::string> output = CXXIter::from(input1) .copied() .zip(CXXIter::from(input2).copied()) .collect<std::unordered_map>(); // output == { {1337, "1337"}, {42, "42"}, {128, "128"} }
- fmtlog A log Library Based on fmt library has extremely low latency and fast speed. Due to design reasons (consumption queue), too fast log speed will lead to log loss, but the idea is still very interesting. nanolog, but it's faster
- KDBindings A library that separates signal slot into a component can facilitate desktop programming, especially in scenes that are inconvenient to use qt
- fuss A simple pubsub implementation, nothing special, is called by function
- libsigcplusplus c++17 signal processing library, there won't be anyone who doesn't use c++17 now
- compile time bounded integers Compile time calculation library
constexpr cbi::Bounded<int32_t, 1, 10> fst{ 2 }; constexpr cbi::Bounded<int32_t, 1, 6> sec{ 2 }; auto res = fst + sec; // Bounds are calculated automatically based on the operation using expected_t = cbi::Bounded<int32_t, 2, 16>; static_assert(std::same_as<expected_t, decltype(res)>); assert(res.get() == 4); // extract runtime value const std::optional shrinked = res.shrink_bounds<1, 5>(); // shrink bounds assert(shrinked.has_value());
But can anyone really use it