« first day (422 days earlier)      last day (4509 days later) » 

12:38 AM
#include <vector>
#include <memory>

int main() {
    using ptr_int = std::unique_ptr<int>;
    std::vector<ptr_int> v { ptr_int(), ptr_int(), ptr_int() };
} // fails because unique_ptr has no copy ctor
Hmm, cannot move with list initialization?
Or is GCC not conformant here?
 
"Yes" on which one?
 
No idea.
 
Xeo
lol
 
@RMartinhoFernandes "conforming"!
@RMartinhoFernandes Initializer lists are always passed by copy
 
12:49 AM
@KerrekSB Want some rep? I just pressed "Submit" on a question!
0
Q: Can I list-initialize a vector of move-only type?

R. Martinho FernandesIf I pass the following code through my GCC 4.7 snapshot, it tries to copy the unique_ptrs into the vector. #include <vector> #include <memory> int main() { using move_only = std::unique_ptr<int>; std::vector<move_only> v { move_only(), move_only(), move_only() }...

 
I'm trying to find a coding blog post that involved pushing dough between conveyor belts in a bathtub. Ring a bell to anyone?
 
That sounds nasty.
 
What.
 
It had something to do with giving users a sense of control, I think.
Or maybe it was that the little things add up to make our days horrible.
Probably that.
 
@RMartinhoFernandes Repped!
 
12:57 AM
@KerrekSB Thanks. Can you think of an alternative that doesn't involve looping?
 
@RMartinhoFernandes No.
 
You mean like populating the internal array of a vector directly?
That'd defeat the purpose of the allocator.
 
I'm trying to initialize a member vector from a parameter pack.
 
Xeo
gimme a sec
 
12:59 AM
Looping on that involves some machinery I'd rather not pull out if at all possible.
 
Xeo
template<class T>
struct mover{
  T&& _val;
  mover(T&& v)
    : _val(v) {}

  explicit operator T() const{
    return T{std::move(_val)};
  }
};

template<class T>
mover<T> make_mover(T&& v){
  return mover<T>{v};
}
Should work if you only use it for the intended purpose :P
 
Sounds like Ubik.
 
Xeo
can be improved ofc
 
@Xeo How does the vector code know not to copy that?
Maybe I need an example of usage :)
 
Xeo
vector<T>{ make_mover(move_only()), make_mover(move_only()) };
explicit conversion to T, only holds onto rvalues
should theoretically work
 
1:05 AM
I've always heard so much about C Script, but I never took the time to learn it. Frankly, I know nothing about it. I'm more into JavaScript. C Script is a whole other world away, isn't it?
 
Xeo
wtf C Script?
 
C++?
 
What.
 
I've been here only about a minute and I already feel stupid. o3o
 
C++ and JS don't have anything in common, maybe except parts of syntax.
But that's irrelevant anyway.
 
1:07 AM
@Xeo Hmm, lemme try that.
 
Well, I have done a lot of scripting on Windows XP, besides the basic web development, so I know a little bit about the framework Windows offers. Doesn't C++ offer a lot in projects on Windows computers?
 
Xeo
I think you're mixing up "scripting" and "programming" here
 
What's the difference?
 
"Scripting" is poorly defined.
 
It's a "you know it when you see it" thing.
@Xeo Nope, that doesn't fit the initializer_list overload.
 
Xeo
1:11 AM
Hm, strange
maybe an extra pair of {}?
Or simply ()
 
> note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::initializer_list<std::unique_ptr<int> >'
Nope.
@Xeo Tried that.
 
Xeo
Can't test the code unfortunately, no compiler with init list support here
I don't understand why it won't work. :(
 
Because!
 
Xeo
maybe try std::initializer_list<mover<move_only>> il{ same_stuff_here }; vector<move_only> v{il}; ?
 
There's no conversion between std::initializer_list<mover<move_only>> and std::initializer_list<move_only>.
 
Xeo
1:14 AM
then use il.begin(), il.end()
atleast that should work
 
Oh, silly.
Ok, time to stuff yet another lambda into a ctor member init list.
Thanks.
 
Xeo
lol
Does it work?
 
Xeo
/crosses fingers
Y'know, I wonder... what's the "innermost enclosing scope" in the following example?
struct foo{
  int a;
  foo() : a([]{ return 42; }) {}
};
aka, in what scope is the closure type of the lambda defined?
I'm also wondering why there is no template<class U> initializer_list(initializer_list<U> const& other) conversion copy ctor.
 
It workses. Once I fixed your broken mover code :P
 
Xeo
1:19 AM
strange stuff with the initializer list
 
Named rvalue references are lvalues.
Star that.
 
Xeo
So?
ah
_val(v) won't work without move then?
 
Xeo
strange stuff
I think of them as normal lvalue references all the time
int& val;
foo(int& v) : val(v) {} // A-OK
so I thought the same would apply to them
oh well
 
If you post your workaround as an answer, I'll +1 it.
 
Xeo
1:21 AM
omw
 
Is it right that in C there is no legal analogue of a const_cast?
I.e. if I have a T const *, I cannot possibly get a T * from it?
 
Can C++ be ran directly from a file on Windows, like JS?
 
@KerrekSB Can't you "just cast it"?
@Mikett Normally, C++ files need to be compiled into .exes first.
 
@RMartinhoFernandes No, gives me a warning, i.e. an error (with -Werror)
 
Ah, I've just noticed a lot of jobs like you to know C++, and the only cross-platform script I know is JavaScript. I know VBScript, but it isn't cross-platform.
 
1:24 AM
But in C++, a C-style cast can cast const away, right?
 
@RMartinhoFernandes That's only because in C++ a C-style cast is a Magic Thing that tried several different C++ casts...
 
Well, I thought it was because in C everything was possible :)
So, C++ C-style casts are even eviler than C casts.
 
@RMartinhoFernandes Well, it triggers a warning in GCC. I'm not actually sure what the standard says.
 
Can you cast T const* to void*?
Or must it be void const*?
 
@RMartinhoFernandes Must be const
I'm trying to fix some warnings in this old code. They use a constant array, but want to write something into an unused end of the array....
 
Xeo
1:30 AM
0
A: Can I list-initialize a vector of move-only type?

XeoWe're gonna utilize a little helper type here: #include <utility> template<class T> struct mover { // warning, very volatile, use with care mover(T&& v) : _val(std::move(v)) {} explicit operator T() const{ return T{ std::move(_val) }; } private: T&&...

@RMartinhoFernandes Done :)
 
What about *(T**)(void*)&ptr? Is this legal?
 
Xeo
@RMartinhoFernandes Oh my gosh C...
 
POSIX uses something like this to convert void* to a function pointer.
@Xeo Yep, that's ugly as heck :)
 
Xeo
But I have the feeling my mover up there isn't really any prettier ;)
It is just packaged in a nicer way
0
A: A C++ Library similiar to C# .NET

UhriahTheSecondC++ is a complicated programming language. If you are looking for something that resembles C#/Java it is probably best to just use C#/Java and save yourself the headache.

oh boy
 
POSIX is very C-oriented.
And they ran out of vowels in the middle of it.
 
1:35 AM
@Xeo I'm keeping it in namespace ubik.
Ubik ( ) is a 1969 science fiction novel by American writer Philip K. Dick. Critic Lev Grossman described it as "a deeply unsettling existential horror story, a nightmare you'll never be sure you've woken up from." Plot synopsis The novel takes place in the "North American Confederation" of 1992, wherein technology has advanced to the extent of permitting civilians to reach the Moon and psi phenomena are common. The protagonist is Joe Chip, a debt-ridden technician for Glen Runciter's "prudence organization", which employs people with the ability to block certain psychic powers (as in th...
 
Xeo
lawl
 
> Ubik makes breakfast a feast, puts zing into your thing. Safe when handled as directed.
> In the interest of completeness I'll mention wxWidgets. It's designed originally for guis but is now general purpose. – Matt Phillips yesterday
How long before wxWidgets starts to read mail?
 
Can I have -Werrors in GCC but not have pedantic warnings be errors?
 
I thought that was the default.
 
Well, I still want pedantic warnings
But I don't want those to be errors
Like -no-pedantic-errors -pedantic -Werror or so
 
Xeo
1:46 AM
@RMartinhoFernandes, can you test the edited code in my answer again? I changed it a bit and added a little enable_if
To make rref only usable on temporaries
 
Won't T&& be enough for that?
Oh, the function.
Why not add a better match for lvalues, and delete it?
 
Xeo
@RMartinhoFernandes Can you even delete non-member functions?
 
Yes, you can delete everything!
rref_wrapper<T> rref(T const& v) = delete;?
 
Xeo
cool. I still think rref(T&& v) would be a better match for T& where T is non-const
 
huh, i got "enlightened" badge for old answer
 
Xeo
1:52 AM
would have to test that
brb
 
not particularly good but i quoted bjarne
11
A: Rationale of enforcing some operators to be members

Alf P. SteinbachThe four operators mentioned in the original posting, =, (), -> and [], must indeed be implemented as non-static member functions (by respectively C++98 §13.5.3/1, §13.5.4/1, §13.5.5/1 and §13.5.6/1). Bjarne Stroustrup's rationale was, as I recall from earlier debates on the subject, to retai...

 
Xeo
The OP edited the question earlier today (or yesterday)
so it got a little more views
 
I think, the nice thing about C++ subtleties is that one can always just ask Bjarne as last resort
which is what i did there
but with SO replacing Usenet that kind of thing has become much more rare, I gather
so many thousands of folks now asking questions
about mostly trivia
 
Xeo
@RMartinhoFernandes I would need the SFINAE anyways, since rref(T&&) and rref(T&) is ambiguous for lvalues.
 
Xeo
1:59 AM
and if I use rref(T const&) instead of rref(T&), the T&& overload is used for non-const lvalue refs
 
Then delete the lvalue ctor, and foward from the function.
 
Xeo
template<class T>
typename std::enable_if<
  !std::is_lvalue_reference<T>::value,
  rref_wrapper<T>
>::type rref(T&& v){
  return rref_wrapper<T>(std::move(v));
}

template<class T>
rref_wrapper<T> rref(T& v) = delete;
does the job
But I get an unsettling warning with MSVC
 
Yep, deleting the bad ctor is exactly what the std::reference_wrapper does.
 
Xeo
> warning C4413: 'rref_wrapper<T>::_val' : reference member is initialized to a temporary that doesn't persist after the constructor exits
int main(){
    int x;
    int& y = x;
    int&& z = std::move(x);
    rref_wrapper<int> m1(rref(x)); // warning here
    rref_wrapper<int> m2(rref(y));
    rref_wrapper<int> m3(rref(int()));
}
 
That warning sounds sensible, but were doing the nasties on purpose.
 
Xeo
2:02 AM
but the first case doesn't link anyways, so everything is fine
 
"Safe when handled as directed."
 
Xeo
LOL fuck MSVC
  rref_wrapper<int> m3(rref(int()));
complains too :<
anyways, it should theoretically work if used like in the question/answer
since the temporaries should life until the end of the full expression
 
    template <typename T, typename... Args>
    T move_init_list(Args&&... args) {
        std::initializer_list<mover<typename T::value_type>> l {
            std::forward<Args>(args)...
        };
        return T { l.begin(), l.end() };
    }
Wrote this one. Needs a better name.
 
Xeo
looks sweet, can't think of a better name though
 
Oops, I forgot the calls to make_mover.
 
Xeo
2:06 AM
heh
 
But the ctor is implicit.
 
Xeo
I made it explicit in the edited code
it's better that way
 
Xeo
atleast I thought I did
 
Xeo
2:07 AM
Ah, I did in MSVC :D
There, done
all changes incorporated
Did you also change the operator T&&? I think that's an important change since it saves a move / copy
copy for types where moving wouldn't do anything useful anyways, aka flat types
Damn, when writing C++ code I naturally want to optimize everything to the last bit
 
Nope, that seems to break it.
Ends up here.
std::__uninitialized_copy_a(__first, __last,
    this->_M_impl._M_start,
    _M_get_Tp_allocator());
Initializer list iterators are not move iterators.
They're pointers, so a dereference always yields an lvalue.
There are no rvalue pointers :(
 
Xeo
Ahh, I see, damn
I thought I'd be witty here. :(
 
2:27 AM
Can an exception's ctor throw exceptions?
I mean, I know such code is possible, but is it bad if it does?
 
Xeo
Theoretically everything should be fine
since the first exception isn't yet thrown
If the copy constructor throws however...
No, that would also be interesting
try{
  throw except(); // copy ctor throws
}catch(except e){ // except already catched?
}
 
I don't catch exceptions by value.
 
@RMartinhoFernandes it is ok technically, but it is of course bad: you get a different exception than you wanted, losing information
 
@Xeo The copy can be ellided.
 
Xeo
If except was caught when the copy ctor is invoked, then normal exception propagation would happen, i.e. the new exception would replace the old one. If it doesn't count as caught, you got std::terminate
 
2:30 AM
"caught".
 
Xeo
details
 
Xeo
2:49 AM
This has proven to be an interesting read
Though I don't want to know the performance of that...
 
Seriously, what's the point in grabbing C++, stripping it of everything C++ and add totally un-C++ stuff?
 
dunno. ask the java folks. :)
 
Xeo
I thought of creating something similar actually, but a bit moe C++ish. Just for fun and trying to create a scripting language.
 
youtube.com/watch?v=y71lli8MS8s :/ I have no idea of 50% that is going on in the video. It is C++11 if you want to check it out, lots of templates.
@Xeo, is that what you meant with something more C++ish?
 
Xeo
3:20 AM
@fabianhjr Fuck, that is awesome. If only all those magic numbers didn't exist...
 
Well, as I said I don't yet understand his emulator. It looks awesome, however many concepts evade me.
@Xeo do you live from coding? I am just getting started and want to break into the industry.
 
Xeo
Currently unemployed, just finished my tuition recently
 
Well, I am in the middle of HS, curretly learning Computer Graphics and Networking basics. (C++/Qt + OpenGL, Python, NodeJS/Express + Socket.io, HTML5/CSS3)
@Xeo what are you doing to land a job?
And what have or haven't help you.
 
3:48 AM
@Xeo you seem not so much unemployed as unpaid
 
Xeo
@keithlayne Why?
 
@Xeo, where are you from? USA? I am from Mexico City.
 
Xeo
Europe
 
you do a lot around here...you're like a free C++ consultant
 
:/ A lot of people here look like consultants.
 
Xeo
3:49 AM
Meh, I like SO. It broadens my horizon and I learn a lot
 
you're probably underpaid as a babysitter too :)
 
Xeo
That's for sure.
"Mimimi, how can you demand payment for watching your little brother? He's family! mimimi."
>_>"
 
you should strike...oh wait, that may not end up so well
Mimimi?
 
Xeo
"mimimi" = "senseless complaining"
 
oh...somehow that didn't translate in my head
 
Xeo
3:53 AM
Anyways, I need to get some sleep, see ya
 
later dude
 
@keithlayne what are you up to?
 
perusing the interwebs
 
Nice, so how is CS going for you?
 
meh
I've been doing other stuff for years, there's a lot to catch up on. I'm currently playing with the new c++11 features and changes
 
3:58 AM
Why so? Or are you talking about school/college/university?
:/ I don't even know the changes. I am barely standing up with programming.
 
no, I was in the army for 9 years, hadn't programmed much, a lot has changed. I'll be back in school in January.
you're young, I was studying CS the first time when you were in diapers
 
Why 9? Volunteered? What did you did in there? Officer? Medic?
 
In the US, everybody's a volunteer. What I did was exceptionally boring, I don't like to talk about it.
 
Ok, well, in Mexico everyone must serve 1 year. :/
Only salvation is if you get randomly selected for the reserves.
Then you are enlisted but you really don't even have to go anywhere and continue with life.
 
I don't think that's a bad thing
 
4:02 AM
33 - 16 = 17? Did you started with C++?
 
I know you don't have kids, but you stay in diapers for more than a day
When I was in college I learned C++, not immediately, but liked it
 
[quote]the first time when you were in diapers[/quote]
 
Blah, I can't make this work. I'm going to sleep. Good night everyone.
 
Nice to know.
Night
 
I was stationed in El Paso for most of that time...right next to Juarez, that is a scary place.
 
4:05 AM
I know, don't worry.
Though now I am sure you didn't made a lot.
 
what do you mean?
 
Well, the narco crosses but the violence is not really up the border.
Now everyone here is shitting themselves for the OpCorrupcion of Anon and their threat to release names. If that does happen shit will hit the fan.
Some justice on one owns hand is starting to cause problems.
 
I hope things can be fixed in places like Chihuahua
 
Chihuahua is fine.
 
Except for Juarez?
 
4:09 AM
Yeah
 
okay
 
Jalisco and Monterrey are in trouble.
S.A. of R.L. and big S.A. de C.V are starting to move headquarters back to Mexico City.
 
I'm glad it's not my job to fix those problems...I don't know if there is a satisfactory solution
 
Legalizing pot is a start.
 
That may be satisfactory to you, but not everyone will agree.
 
4:12 AM
Last time Felipe Calderon tried talking about it Obama put threats to remove all support(humanitarian included) and start asking for their gifted toys(Blackhawks and other mil stuff) back, even if it was "gifted"
Well, why not?
 
you can't beat opinions into peoples' heads
nobody wants advanced military technology in the hands of a potentially failed state.
 
Well, still I don't care what they think, if they are non users I am not forcing them to smoke.
Here the important thing is to cut funding from organized crime groups.
 
good luck with that
 
Well, blackhawks are used primarly to move supplies to isolated comunities after a dissaster, and we produce our own service rifle.
The FX-05 "Xiuhcoatl" (literally, "turquoise-serpent" in Classical Nahuatl; metaphorically or descriptively, "fire serpent") is a Mexican assault rifle, designed and built by the Dirección General de Industria Militar del Ejército (General Bureau of the Army Military Industry). The rifle was officially presented in the military parade on September 16, 2006, in the hands of the Special Forces Airmobile Group, GAFE. (Grupo Aeromóvil de Fuerzas Especiales). Development The development of the FX-05 began as a 16-month research back in 2005 with CIADTIM as part of research efforts to rep...
H&K wanted it banned and destroyed because they alleged it infringed on their designs, after they inspected them it turned out to have totally different internals.
@keithlayne night
 
cpx
Hm.
 
4:28 AM
@cpx ?
 
WTF is Asterisk and Obelisk?
 
I have a base class Piece which contains a Point. It's used in an STL container, and it is uniquely identified by its point. The question is: what data-structure should I use? If I use a set and need to swap an item, I have to remove the item and stick it back in again. If I use a map, I have to duplicate the point to map from point to piece. Thoughts?
 
you can use a custom sort predicate
but perhaps better advice, don't fret about the small stuff
 
Oh, I'm not fretting.
 
a little duplication of point data probably doesn't matter much if at all :-)
 
4:38 AM
This is a chess game that isn't prioritized for performance.
I'm currently using a map of points to pieces
but pieces don't contain their points
It works just fine
but it gets really verbose in some of my functions.
I was redoing it to a set
but then I discovered that in a set calling insert on an item already in the set will not swap out the item currently there.
That's just nasty for my uses.
Maybe ideal for others.
But not for this case.
 
5:07 AM
Do you guys know of any good libusb-win32 documentation?
Oops now got it, couldn't access the website before, timeout error.
 
6:00 AM
@IntermediateHacker Asterisk is a software implementation of telephone private branch exchange. I don't know about obelisk but I think it is similar to a PBX
 
6:46 AM
How can I copy a base class pointer? I can't seem to figure this out.
 
cpx
@LeviMorrison is it a private member?
 
No.
It's also an abstract base class.
new AbsBaseClass won't be working :/
Otherwise a copy constructor would be great;
 
7:07 AM
virtual AbsBaseClass* clone() = 0; Is how I got it to work, I guess. Seems lame, but it works. Oh well.
 
cpx
7:53 AM
Hm.
imagine if there's a badge for "closing 100 questions" all questions will be closed. lol
 
@cpx right
 
 
2 hours later…
9:44 AM
1
Q: Is a function return-value constant by default (an rvalue)?

xcryptI'm learning about rvalue references, and the tutorial told me this: X foo(); X x; x = foo(); Rather obviously, it would be ok, and much more efficient, to swap resource pointers (handles) between x and the temporary, and then let the temporary's destructor destruct x's original resourc...

I downvoted the accepted answer and provided a comment
 
cpx
cout << function << endl; outputs 1 always hm
I was an expecting an address :s
 
Function pointers are converted to bool, it would seem.
Remember that a function pointer is not a pointer in the regular sense.
You cannot store function pointers in void pointers, for example.
 
oooh, so we going on the assumption that function is the name of a function, I can fly with that
 
cpx
yes, nota member pointer it seems
static members can be pointers
 
Are you talking about static members that are pointers, or pointers to static members?
 
cpx
9:48 AM
pointers to static members
 
Those are just like pointers to non-members.
@JohannesSchaublitb Thank god for your careful observation ability :)
 
cpx
but cout << (int)function << endl works
I wants hexadecimal address :/!
 
cout << std::hex << ...
 
Note that a function pointer may be much more complicated than a simple address.
 
9:58 AM
@IntermediateHacker clearly not a rip of, spelt very differently
 
but it's almost completely a copy of the Google website!
 

« first day (422 days earlier)      last day (4509 days later) »