« first day (1656 days earlier)      last day (1203 days later) » 

12:35 AM
Also would better if const char* rather than std::string.. A better approach is to use #defines to capture the call site or boost backtrace: #define api_invalid_argument(msg) _api_error_handler<std::invalid_argument>(__FILE__,__LINE__,"invalid argument",msg)
</unsolicited code review>
 
1:21 AM
I am shocked that std::make_unique is not implemented in C++11 whereas there is a std::make_shared in C++11.
 
1:35 AM
51
Q: Why does C++11 have `make_shared` but not `make_unique`

Šimon Tóth Possible Duplicate: make_unique and perfect forwarding Why does C++11 have a make_shared template, but not a make_unique template? This makes code very inconsistent. auto x = make_shared<string>("abc"); auto y = unique_ptr<string>(new string("abc"));

>> According to Herb Sutter in this article it was "partly an oversight".
 
2:24 AM
@Mikhail Thank you. There is a implementation in one of the answers. For your convenience, here it is:
template<typename T, typename ...Args>
std::unique_ptr<T> make_unique( Args&& ...args )
{
return std::unique_ptr<T>( new T( std::forward<Args>(args)... ) );
}
 
Can't tell if you're trolling :-)
 
Is there any potential problem in this implementation?
There is comment: I updated it, but the new version does not have the sample implementation included in this answer
:51429734
 
3:16 AM
@Mikhail @Mikhail Is there any potential problem in this implementation?
 
3:59 AM
@John It doesn't work for std::unique_ptr<T[]>.
You can't std::make_unique<char[]>(10);
What I mean to say is with the standard implementation you can do std::make_unique<char[]>(10); but with your make_unique you cannot.
 
 
2 hours later…
6:18 AM
@FrançoisAndrieux Is it possible to make it work for T[]?
@FrançoisAndrieux How to improve it?
 
 
1 hour later…
7:22 AM
why do I have to pass as first parameter "this" in the following function ? void rise ( Callback< void()> func )
like there is no sign for me in the header file
 
 
3 hours later…
nwp
9:58 AM
@CătălinaSîrbu Check the definition of Callback.
It's probably a templated using declaration that takes the given parameters and adds some class parameter to it.
 
 
2 hours later…
12:07 PM
https://en.cppreference.com/w/cpp/algorithm/nth_element

> All of the elements before this new nth element are less than or equal to the elements after the new nth element.

> 1) Elements are compared using operator<.

Aren't these two contradicting?
or maybe not but I found this very confusing and has cost me two hours worth of time
 
nwp
When they say "Elements are compared using operator<" they mean "The algorithm used operator< to determine the order", not "operator< will return true for all consecutive pairs".
 
"less than or equal" can be figured using just the less than (a < b and b < a)
@nwp Yeah, this is what I realized. I thought nth_element would partition according to the < operator by default. Even though the default operator is <, it partitions according to <=.
Is there a reason why it's defined in this confusing way? What's the issue if the default operator was <= or nth_element ordered according to just <?
 
nwp
It doesn't really matter which operator you take between <, <=, >, >=, so most things try to only use < so you don't have to define all of them.
I guess in C++20 this matters less.
 
1:13 PM
Probably with two different overload, along with `std::enable_if`. The MSVC implementation I am looking at is
template<class _Ty,
enable_if_t<is_array_v<_Ty> && extent_v<_Ty> == 0, int> = 0>
_NODISCARD inline unique_ptr<_Ty> make_unique(size_t _Size)
{ // make a unique_ptr
typedef remove_extent_t<_Ty> _Elem;
return (unique_ptr<_Ty>(new _Elem[_Size]()));
}
That's the overload for arrays.
You would have the inverse enable_if for the normal make_unique.
 
 
4 hours later…
5:08 PM
@Yashas Let's say you're looking for the tenth element in the array. When sorted, that would be the value 17. But there are 3 elements with the value 17 in the array. The elements will be arranged so that one of those elements with the value 17 is in the tenth spot. It also guarantees that all values less than 17 will be somewhere in array[0] through array[8], and all values greater than 17 will be somewhere in array[10] through array[array_size].
But it doesn't guarantee anything about the other elements with the value 17. They could be in either the "lower" or "upper" parts of the array--and given a total of three (or more) some could be in the lower part, and some in the upper part.
It depends on the positions the elements would be in if you sorted the entire array. If the position you've given would be the beginning of that run of equal elements, then you'll end up with one of them in the specified position, and the others on the "high" side. If the position you specified would be the end of the run, then they'll all be on the "low" side. And if you specified somewhere in the middle of the run, then some will be in the low, and others on the high side.
 

« first day (1656 days earlier)      last day (1203 days later) »