Nils
Do not use rand and time
It's recommended by reference
Anonymous
It's recommended by reference
no. use C++ random number engines
Anonymous
why?
Rand has bad distribution Time is just C API, meh
Anonymous
There are <random> and <chrono>
klimi
but if i just want to get "random" number, not for crypto... is it bad to use rand? do i need some other lib in c?
klimi
indeed
Anonymous
that is a good point, working on that
You can use smart pointer "idiom" Constructors for creating single_view from existing object And make_single_view template function to create object with args
Nils
What reference?
https://en.cppreference.com/mwiki/index.php?title=cpp/numeric/random/rand
Anonymous
But I dunno how to combine storing a reference/pointer to existing object or newly created object
Anonymous
But I don't think that you even should provide this feature with make_single_view
Anonymous
https://en.cppreference.com/mwiki/index.php?title=cpp/numeric/random/rand
It doesn't recommend anything It's just a reference
Anonymous
https://en.cppreference.com/mwiki/index.php?title=cpp/numeric/random/rand
Every sane C++ developer recommends you not to use rand
Anonymous
But I don't think that you even should provide this feature with make_single_view
I mean view is semantically meant to be created from an existing object Like std::string_view, std::span
Anonymous
But I dunno how to combine storing a reference/pointer to existing object or newly created object
i can keep two pointers, one unique_ptr and one normal pointer. for objects created with make_single_view unique_ptr will own the object and the normal pointer will contain result of unique_ptr::get(). for pointers directly passed to single_view the smart pointer will remain nullptr.
Anonymous
I mean view is semantically meant to be created from an existing object Like std::string_view, std::span
the std::single_view actually requires T to be copy constructible. there is also std::iota_view
Nils
std::string res = "0000000000"; Error: no viable conversion from 'const char [11]' to 'std::string' (aka 'basic_string<char>') WTF?
Nils
probably mistake before this line
The line before: std::string randidgen() {
Nils
Paste the whole code
Solved already, it was a problem with my IDE
Anonymous
I don't like it, because there is unnecessary memory allocation
yes. but i don't see any other way for me to simultaneously work on objects i own and not own
Anonymous
one more way might be
Anonymous
Anonymous
reading
Anonymous
What about this?
1) it's C++17, i wanted C++11 compatibility. 2) i think that will get overcomplicated with std::holds_alternative once every 2 lines in the iterator template
☬ੴ Bassi
C++ 20 is out or soon? My head phones need replacing as the cable is loose inside
Anonymous
1) it's C++17, i wanted C++11 compatibility. 2) i think that will get overcomplicated with std::holds_alternative once every 2 lines in the iterator template
actually 2 might not be the case. only the begin and end functions of the view would need replacement. but still it's C++17 only
☬ੴ Bassi
https://www.modernescpp.com/index.php/c-20-an-overview
Anonymous
What
I think he wants write a cable for his headphones with C++20
☬ੴ Bassi
I was listening to a podcast. But my head phones are broken. So I thought I could ask here if it's releaed
☬ੴ Bassi
And does clang support it
Anonymous
C++ 20 is out or soon? My head phones need replacing as the cable is loose inside
C++20 standard is closed afaik but none of the compilers supports it fully
☬ੴ Bassi
Ty
Anonymous
And does clang support it
https://en.cppreference.com/w/cpp/compiler_support
☬ੴ Bassi
tyvm
Anonymous
https://en.cppreference.com/w/cpp/compiler_support
GCC has really good support for C++20
Anonymous
I wonder why other compilers are so slow...
Anonymous
Because they implement more
Anonymous
Anonymous
What do you mean?
GCC doesn't have comparable features to others
Anonymous
The only thing clang hasn't implemented is stack probing on arm64 from what I'm aware
Anonymous
Otherwise GCC doesn't have half of clang's sanitizers, no thinlto and is missing a lot more when it comes to not breaking code
Nils
Just out of interest, is it possible to generate random data out of undefined behavior?
Anonymous
Just out of interest, is it possible to generate random data out of undefined behavior?
no. then undefined behaviour will be defined as "produces random data". this is a contradiction since undefined behaviour is by definition undefined
Anonymous
So notstd::single_view can be creates a new object, but what if I want to create it from already existing object? Only copy?
technically an user can use range/view functions from the STL to create a range that doesn't own the object. then they can pass that range to my single_view. they can also pass a pointer to my single_view
Nils
oh
Nils
nvm then 😂
Anonymous
But that would not reliabily be random data, right? And it could cause a segmentation fault.
i mean it can cause segmentation fault. but so can std::string_view and other STL views that don't own the object
Anonymous
Hi, can someone help me? I need to create copying comstructor to this class
Anonymous
template<typename T> class SSL { struct Node { T data; Node* next; }; Node* head = nullptr; public: // ... };
Anonymous
That creating deep copy of the transmitted object
Anonymous
Can someone help with this?
Dima
Hi, can someone help me? I need to create copying comstructor to this class
Check out cppreference site to see about copy constructors
Anonymous
I check thisand really dont know how to make deep copying constructor for this class...
Ak
Help me to make flowchart and pseudocode for my mini project
Hermann
i dont understand gmp export. is mpz_export(buffer, NULL, 1,1, 0, 0, mydatampz); correct?
Hermann
size of mydatampz is 1024 but buffer use 128 slot of 1024
Hermann
i dont understand gmp export. is mpz_export(buffer, NULL, 1,1, 0, 0, mydatampz); correct?
https://gmplib.org/manual/Integer-Import-and-Export#Integer-Import-and-Export
Nils
Hi, any idea why "thisсlient->user" results in "stray '\201' in program"?
Nils
solved, с != c
Hermann
what happens if i only use 128 slots of an array of 1024 ?. does the rest of the memory remain accessible?
Victor
Yes
Palinuro
what happens if i only use 128 slots of an array of 1024 ?. does the rest of the memory remain accessible?
if you allocate 1024 slots, you have all the slots assigned to that array and only that array will have such slots reserved if your code does not actually use all of them, it is a choice you make at a logic level and other components of the program will not be able to benefit from that memory, that is actually wasted it is your responsibility to decide wether such a waste is convenient and acceptable or not
Palinuro
what happens if i only use 128 slots of an array of 1024 ?. does the rest of the memory remain accessible?
otherwise you have to reallocate the array in a smaller memory region, but reallocations are not an efficient process