« first day (469 days earlier)      last day (4494 days later) » 

4:27 PM
Define assert to something else.
Oh wait, there's also _CrtSetReportMode that can disable it.
Standard assert sucks anyway.
 
@CatPlusPlus I know that best practices is to use one own's assertions, since it's the kind of thing that, like log reporting, is very much needed but different from one application to the other. However, unlike log reporting, I've never seen a C++ 'library' for assertions.
 
Let's write one.
 
I usually just do #define my_assert(expr) do { if (!(expr)) some_kind_of_breakpoint_intrinsic(); } while (false)
I did GUI window once, but meh.
 
What's would be the aims of an assertion solution? Allows assertion site to possibly build a nice assertion message (with relevant information like function & line), and allows several behaviours to be switched out project-wide?
 
To me the most important thing is that it should break on the assert callsite, not somewhere within the library code.
 
4:35 PM
I have a reasonably sizeable custom asserter implementaiton in one project
 
Xeo
And I think it would be important that the behaviour stays (mostly) the same across different platforms (if possible)
 
I don't need messages if the debugger can show me everything.
 
that mostly just hooked into the unit testing frame work I had better though
 
@CatPlusPlus I've never introduced a breakpoint with GCC in my code. What does that look like?
 
Dunno, TBH. MSVC has __debugbreak() instrinsic.
 
4:37 PM
You could always just raise a SIGINT or something.
 
So far: assertions that set off a breakpoint; silent assertions; 'standard' runtime assertion (interrupt handler/quick exit)?
 
On x86, in 32-bit code you can do int 3, but dunno how that works in 64-bit modes.
 
7
Q: Is there a portable equivalent to DebugBreak()/__debugbreak?

vividosIn MSVC, DebugBreak() or __debugbreak cause a debugger to break. On x86 it is equivalent to writing "_asm int 3", on x64 it is something different. When compiling with gcc (or any other standard compiler) I want to do a break into debugger, too. Is there a platform independent function or intrins...

 
Xeo
@LucDanton What are silent assertions?
 
@LucDanton Isn't the whole point an assertion to break when something fucks up?
 
4:38 PM
@Xeo Nothing checked, and ideally no code generated.
@EtiennedeMartel Some people have a need for a 'all security measures off' build.
 
Well, it needs to be possible to turn off the entire assert machinery.
 
Xeo
@LucDanton Ah, like assert when NDEBUG is defined?
 
@LucDanton Makes sense in release.
 
Right, exactly like that.
 
Xeo
I thought you meant something like logging instead of a break..
 
4:39 PM
Also, I forgot but also a 'pluggable' mode where a user can just get his or her own handler called on an assertion.
That could do logging, if there's a need for that (hard to imagine though).
"Hey, the program run ran into an invalid state at exactly this point."
 
Xeo
"And then continued happily ever after"
Very hard to imagine
 
Technically, an assert is used to check if you made a mistake in your code.
It should not happen in release.
If an error is caused by the user, then it's better to throw an exception or something.
 
Some environments don't have a console though, so you may need to log the assertion before a quick exit. I guess.
@EtiennedeMartel Since we're talking about a hypothetical library, any mention of user I've made were referring to the library user. Not the application user (which I would usually refer to with 'end-user').
 
Xeo
But a handler sounds good. With line, file, func as the parameters
 
@Xeo Also assertion message for Assert( cond, "message goes here");.
 
Xeo
4:44 PM
Hm, does the handler really need that message?
 
It's always useful.
 
Xeo
No reason not to provide it I guess, but still
Oh, no, it almost certainly does. Nvm my last message
void assert_handler(char const* file, unsigned line, char const* func, char const* msg);
Anything else?
 
What would be func?
 
I'm okay with a Assert( cond ) overload which generates a generic message though (that is in turn provided to the handler).
 
Xeo
@EtiennedeMartel __func__ in C++11, platform specific macro before that
 
4:46 PM
@LucDanton That default message could be just a stringification of the assertion expression.
 
Xeo
Like __FUNCTION__ for MSVC and __PRETTY_FUNCTION__ for GCC
 
Oh. Interestingu.
 
Mmh, it's not possible to overload a name provided by a macro and have the name + args preprocessed out, is it?
 
Xeo
@LucDanton ?
You mean have both ASSERT(cond) and ASSERT(cond, "message") work?
 
I can imagine that working, but not having that turned into a 'nice' no-op on demand.
 
4:51 PM
2
Q: C Preprocessor, Macro "Overloading"

almosnowI'm trying to do some kind of Macro "Overloading", so that MACRO(something), gets expanded differently than MACRO(something, else). Using a snippet I got from here (I'm not sure if it's 100% portable) and some functions from the Boost PP Library, I was able to make it work :D //THESE TWO COUNT ...

 
Xeo
@LucDanton Why not?
#ifndef NDEBUG
#define ASSERT(...) DISPATCH_ASSERT(__VA_ARGS__)
#else
#define ASSERT(...)
#endif
 
@LucDanton No.
 
Ah yes, variadic macros work for that :)
 
If I get what you mean.
You can't overload macros.
Variadic macros alone won't cut it, you'd need Boost.PP kind of magic.
 
#define NAME some_functor
The name provided by the macro is overloaded, not the macro. Or something. I'm making up the terminology as I go.
 
4:55 PM
Hmm.
But you would need a macro that generate shit. After all, you need the file, line number, etc..
 
Xeo
@EtiennedeMartel And most importantly, you need to break at the callsite
 
#define NAME some_functor_type { __func__, __FILE__ }
 
Yes. That's the most important point.
So you just can't delegate that to a function/functor. The macro must generate the code.
 
@LucDanton And then the rest of arguments go where?
 
Xeo
@CatPlusPlus To the function call operator
 
4:57 PM
Also, MSVC support for variadic macros kinda sucks.
 
Xeo
7
Q: Variadic macro argument count macro fails in VS2010 but works on Ideone?

XeoI got the following implementation to get the number of arguments in a variadic macro (currently limited to 16 args). However, for VS2010 the output is always 1, no matter how many arguments are passed. On Ideone.com, the output is correct, bringing me to the conclusion that I must have missed so...

So it does.
 
Yes, that.
Though I didn't see that workaround.
 
Xeo
Btw
27
Q: What does the tilde (~) in macros mean?

XeoSeen on this site, the code shows macro invocations using a tilde in parentheses: HAS_COMMA(_TRIGGER_PARENTHESIS_ __VA_ARGS__ (~)) // ^^^ What does it mean / do? I suspect it to just be an empty argument, but I'm not sure. Is it maybe specific to C(99) ...

 
We're already messing with platform specific stuff, so it wouldn't be much of a problem to handle MSVC's deficiencies.
 
Xeo
The linked site is a macro that allows you to see if a variadic macro contains a comma in the arguments, and expands to the 0 or 1 in that case
With that, you can achieve overloading
 
5:01 PM
I'd rather not introduce Boost.PP stuff at each assertion site :)
 
It's not that heavy, if you only include what's actually used.
 
Xeo
#define ASSERT(...) REAL_ASSERT_ ## HAS_COMMA(_TRIGGER_PARENTHESIS_ __VA_ARGS__ (~)) (__VA_ARGS__)
No need for Boost.PP IIRC
 
It's certainly less heavy than any template. :P
 
Xeo
and then #define REAL_ASSERT_0(cond) ... and #define REAL_ASSERT_1(cond, msg) ...
 
I'm le impressed.
 
Xeo
5:03 PM
And since we only need to support 2 arguments, it's rather easy to implement
 
@CatPlusPlus I didn't mean the dependencies, I meant the substitution of the ASSERT and so on.
 
REAL_ASSERT_0 would probably just expand to REAL_ASSERT_1 with some sort of default value for the second parameter.
 
Xeo
Yeah, whatever you fancy
 
Could even be a POO, PILE OF character.
 
Xeo
like #define REAL_ASSERT_0(cond) REAL_ASSERT_1(cond, STRINGIZE(cond))
With the typical STRINGIZE macro
 
5:04 PM
Works like magic.
 
Xeo
Or maybe not even two different ASSERT macros
#define MAKE_ARGS_0(cond) MAKE_ARGS_1(cond, STRINGIZE(cond))
#define MAKE_ARGS_1(cond, msg) cond, msg
#define ASSERT(...) REAL_ASSERT(MAKE_ARGS_ ## HAS_COMMA(_TRIGGER_PARENTHESIS_ __VA_ARGS__ (~)) (__VA_ARGS__))
or something like that
Still, it should be relatively easy
 
Hunger is kicking in. All I head to eat to today were 3 bread rolls (funny word, had to look it up).
 
That macro would expand to a no-op if needed (such as in release).
 
Bread is gooood.
 
Xeo
5:08 PM
@FredOverflow What? Brötchen is bread roll in English? Oh wow...
 
At least according to my Dictionary.
 
Xeo
Yeah, dict.cc agrees
Oh, but it also lists "bun"
 
That word reminds me too much of a certain Mr. Hefner.
"die Brötchen verdienen" is "to bring home the bacon" :)
 
There's 'breadwinner' though, and gagne-pain similarly in French.
 
Meh, stupid iterator invalidation. Are there any proposals to add immutable containers to standard C++?
 
5:12 PM
const std::vector vector = [] -> std::vector { /* fill and return */ }();?
Can a const container invalidate its iterators?
 
Xeo
const_cast<std::vector&>(vector).push_back(haha), but otherwise, no.
@LucDanton Btw const std::vector vec{ /*fill in*/ };
 
@Xeo That's UB!
@Xeo Only works for a fixed, static number of elements.
 
Xeo
And trailing return type in lambda needs explicit parameter list (aka []()->ret{...}) IIRC
@LucDanton Good point
 
@Xeo It does.
 
hi
 
Xeo
5:16 PM
Oh, a name twin to the cat
(if I remember his name correctly)
 
@Xeo A truly immutable container type wouldn't even have a push_back member function ;)
 
I am going to learn a second language. Would you learn Python or Ruby? Going to use is it for "normal" programming problems as well as web applications
 
Xeo
@FredOverflow Well, const Container is immutable enough for me
Your compiler will yell either way if you call push_back - either because it doesn't exist, or because it's a non-const function :>
 
const Container is probably very inefficient. With immutable containers, you can get O(log n) or even O(1) "insertion" depending on the underlying data structure.
 
Xeo
huh?
What "insertion"? Do you mean the building of the container?
 
5:19 PM
Do you speak Haskell? (x:xs) is O(1).
 
@Pjotr why do you asking it in C++ room?
 
@Xeo No I mean getting another container with one more element.
 
@Pjotr use webtoolkit with C++
 
Xeo
@FredOverflow Ah, concatenating it is then. or appending/prepending
 
5:21 PM
I think the term must people would use is consing :) Because the LISP function is called cons.
 
Xeo
@FredOverflow I partly understand Haskell, but I thought of (x:xs) as a function parameter here :P
 
No, function parameters do not need parenthesis in Haskell.
 
You can always use std::tuple then. The unfortunate part is that there's no algorithm for it.
 
@awoodland I would like to extend the programming language knowledge that I have. I want to learn a second language
 
Xeo
Still, good point about making a new container out of an old one. However, that won't work in C++, since it's not garbage collected and as such you can't just create a new container from an old one without explicitly binding the lifetime of the old one to the new one
imagine this:
immutable_vector<int> v1{ 1, 2, 3 };
immutable_vector<int> v2(0, v1);
return v2;
 
5:24 PM
Sure, immutable containers would almost certainly need to be implemented as proxy/handle objects to shared immutable state or something. Not very C++ish, I know.
 
shared_ptr would work fine
if there's no mutation of the objects, then the fact that the internal state is shared is perfectly well encapsulated
 
Right. I would be surprised if there weren't at least half a dozen immutable container libraries for C++ already. Let's pick one of those and make it standard.
 
If we're lucky, it might get into C++3x.
 
@FredOverflow I'd be surprised if you wouldn't be surprised.
 
Xeo
Well then, let's start work on Boost.Immutable!
 
5:26 PM
@LucDanton You mean if I weren't surprised ;)
 
@Xeo No, not Boost. Those guys have to support a bunch of crappy compilers.
 
although i think i would now be ashamed of the coding, i once started on an immutable string class, and it's on sourceforge
 
Xeo
@EtiennedeMartel Okay, then lets call it Boost.NoCrappyCompilers.Immutable
 
Yeah, when I look back at the code I wrote a when I started C++, I cringe.
7
 
anyone who wishes to pick up that glove (or pearls), feel free :)
 
5:30 PM
@EtiennedeMartel I wrote "C++" for years without even knowing that there was such a thing as a standard C++ library. So my code was littered with pointers and manual memory management :)
 
@Xeo What we need is a cool lib with a cool name with a cool looking site that shows a small code snippet and a huge "Fork me on Github!" ribbon in the top right corner.
 
I look back at code I wrote a week ago and I cringe.
 
@CatPlusPlus Never write code when drunk.
 
Xeo
@EtiennedeMartel He's from Poland.
 
Code is best fresh.
Then it goes all green and stinky.
 
5:30 PM
@Xeo What? They're always drunk back there?
 
Xeo
@EtiennedeMartel Google images for "meanwhile in poland"
 
Xeo
Hm
Not what I had in mind.
 
First result.
It's not that bad.
 
Xeo
Anyways, afk.
 
5:42 PM
@FredOverflow Whoops, yeah.
 
morning
 
SO going down for DB maintenance?!? How gay, considering how easy it is to replicate databases these days...
 
Als
Guys
Help needed!
 
Wooohooo - finally converted my memory leak into a SEGV - much easier to debug now 8^)
@Als might have to type quickly - looks like SO going down for maintenance - maybe chat will stay up? I dunno...
 
Als
5:58 PM
@kfmfe04: Chat stays up usually
 
Just stumbled onto Cee Plus Plus, this is going to be a long evening...
 
Als
I installed codeblocks bundled with MinGW but it has a very old 4.4.1 gcc compiler
I want to update it, So how do I?
 
@Als 4.4 isn't that old. I still use 4.2, baha.
 
Als
@EtiennedeMartel: You don't get the goodies with those!
 
user142019
Good evening.
 
6:01 PM
Good afternoon.
 
Als
should use atleast 4.6.something
 
Yeah, for C++11 and shit.
 
Als
Yeah shit that matters?
 
@Als out of curiosity, what do you use MinGW for? Anything Windows specific?
 
@Als latest nuwen MinGW before it was taken down.
 
Als
6:04 PM
@kfmfe04: is a native software port of the GNU Compiler Collection (GCC) and GNU Binutils
@FredOverflow: I actually downloaded 32-bit MinGW-w64 toolchain rubeenv had the link here
 
@Als yes, I know what MinGW is - I used to use it when all I had was a Windows box. These days, vbox+unix_distro(like Ubuntu) is so easy to use that I thought it would make MinGW obsolete.
That's why I was wondering if you were using MinGW for something Windows-specific.
 
Als
@FredOverflow: It seems only have to replace the MinGW folder under codeblocks but seems the folder names are difference once i unzipped the toolchain.
 
Xeo
> Stack Overflow will be going offline for maintenance in a few minutes while we give a database server some love, we should be back in 20-30 minutes
 
Als
@kfmfe04: I just have a windows 7 nothing else
 
Xeo
aka the Hamsters will get some food
 
6:07 PM
@Als if you have enough memory, you can run virtualbox+ubuntu - much less hassle than MinGW
easier updates, more utilities, etc...
vbox + ubuntu can sit on top of your windows 7 so you can shut it down anytime you want
 
Als
@kfmfe04: I have enough memory alrite but what do i exactly install?
 
Xeo
@kfmfe04 Ugh, Ubuntu... :)
 
I use lubuntu + vbox on top of OSX - it runs rock-solid
quite surprising as vbox runs on top of a JVM (with no noticeable slowdown!)
 
Als
@kfmfe04: I see
I should give it a try you think?
 
6:12 PM
aye - sure beats MinGW
you can play with a full fledged *nix variant
 
Als
Please give me a gist of how this works, yeah I am completely unaware of this
 
I actually have two servers that run Ubuntu straight-up, but the vbox + lubuntu on my iMac is much much faster (using multiple i7 cores) so I use this setup for all my builds/devs
ok - the idea is, virtualbox runs a thin-layer emulating the hardware underneath
you install the Lubuntu .iso on top of a virtualbox instead of the hardware itself
as far as Lubuntu is concerned, it thinks it's sitting on hardware, not a virtual machine
the virtual machine that is vbox has drivers to connect to the outside (keyboard drivers, network drivers, video drivers)
so that it behaves correctly on top of your host OS
the host OS can be OSX, Windows 7, etc...
 
> Java is a SyntacticSugar for C/C++.
 
Als
@kfmfe04: Okay How much memory on the harddrive does vbox + ubuntu take, i assume they both reside on harddisk somewhere
 
Xeo
Oh, @FredO found c2.com? :>
 
6:16 PM
Yes, what a mess :) What exactly is this website?
 
@Als you don't need a lot - I think the default is only like 1GB or 1.5GB, but you can configure this every time you start up your vbox
 
Xeo
It's fun.
 
@Als you also designate a file that acts as the HD partition for ubuntu
 
Xeo
@Als vbox itself is small. But for every OS you host, you need a virtual disk.
 
@Als aye - Xeo is a great guy to ask about tight vbox configs!
 
Xeo
6:18 PM
When you create a guest, you can also create a virtual disk. Either normal or dynamic one
 
@Als my vbox has a bloated 10GB of RAM
 
Xeo
@kfmfe04 my host has 2gb.. :<
 
(only because it facilitates my dev - not because it's really needed)
 
Hmm. Apparently StackOverflow has a lonely database server --- "Stack Overflow will be going offline for maintenance in a few minutes while we give a database server some love". Odd way to phrase that.
 
Als
okay I get it, but if ubuntu resides as a virtual disk where does user content reside?
 
6:18 PM
@Xeo that's why I told Als to contact you about tight configs!
 
Xeo
@Als Okay, wait, do you mean memory as in harddisk memory, or as in RAM?
 
Xeo
@FredO, enjoy some sleepless nights
 
@Als you can partition the virtual disk/file up just like you do with a real HD
 
Als
@kfmfe04: Ah I see
 
6:20 PM
21 mins ago, by FredOverflow
Just stumbled onto Cee Plus Plus, this is going to be a long evening...
 
@Als I break my config up into two files, in fact, one for the OS and the other for /home
 
Als
@Xeo: I wanted to ask both how much overhead does it have?
 
@Als but for simplicity, you can put it all on one FS initially
 
Xeo
@Als You can assing how much RAM a guest is allowed to have
 
@FredOverflow A wiki in the truest sense of the word. Not that Wikipedia and clones aren't wikis either, but they've had had to put up with a lot of red tape due to their popularity. Less popular wikis look much more like c2 (tvtropes is a good example, too).
 
Xeo
6:20 PM
vbox itself needs maybe 100 - 150 mb
In fact, my Debian vbox takes 50mb RAM
 
Als
@Xeo: I see
 
@Als Lubuntu is a lightweight variant so will not require much more
 
Als
But then I do have to install gcc on the Lubuntu
 
@LucDanton By the way, did Wikipedia "invent" Wikis?
 
Als
I dont think its bundled in is it?
 
Xeo
6:22 PM
@Als $ sudo apt-get install gcc
Debian Squeeze atleast had a bundled GCC 4.2
 
sudo apt-get install build-essential
 
Als
@Xeo: Yup right
 
lubuntu is so lightweight that you will have to sudo apt-get install build-essential to get it, iirc
but it's totally hands-off/easy, since it's prepackaged
 
Xeo
package managers are awesome.
 
@FredOverflow I was going with 'no', but had to make sure by checking the Wiki article on Wikipedia. Surprise, not only did wikis predate Wikipedia (that's not the surprising part), they were invented by Ward Cunningham, curatof of c2.com!
 
6:23 PM
@Als make sure you get the 64-bit iso when downloading Lubuntu (unless you have an old machine)
@Xeo aye - I agree! It's SO MUCH EASIER than the early days
 
@LucDanton interesting
 
Xeo
Damn you, slow internet...
 
Als
@kfmfe04: Thanks :) Actually it would also mean end to the silly cygwin stuff
 
@Als - np - I remember the pita that was MinGW, myself 8^)
 
Als
:)
 
6:29 PM
Is the book any good?
 
@FredOverflow how old is it? iirc, maybe quite old - in that case, it might only contain the "classic" ways of shooting yourself in the foot with a rope...
 
Maybe I'll buy it just for the funny cover :)
 
Als
Okay SO went down for me.
 
> Possibly the worst book that I have read in my entire life
> Highly Useful; Precisely True; Beginners Please Read This!
a book that polarizes, apparently :)
 
@FredOverflow in other words, a book that speaks the TRUTH
 
6:35 PM
@FredOverflow You can't shoot yourself with a rope. I think you need a gun for that.
 
Did you look at the picture?
 
@Mysticial you are missing the inside joke (the power of C++)
 
oh ic...
lol
 
That's a lot of monitoring monitors..
@FredOverflow the book above sounds interesting enough to read... and I'm desperate lol
 
6:46 PM
@LewsTherin I know, right? :)
 
@FredOverflow Yeah, worth a shot :P
 
@LewsTherin Let me know how it works out for you ;)
 
evening
I wondered, any of you guys ever worked freelance or are freelance?
 
@FredOverflow Yeah, sure :)
 
@TonyTheLion Sam and Max work for the freelance police, if that counts.
 
6:53 PM
wut?
who the fuck are Sam and Max?
I thought we only had metapolice....
 
@FredOverflow bummer rapidlibrary failed me.. Oh well
 
Sam & Max is a media franchise focusing on the fictional characters of Sam and Max, the Freelance Police. The characters, who occupy a universe that parodies American popular culture, were created by Steve Purcell in his youth, and later debuted in a 1987 comic book series. The characters have since been the subject of a graphic adventure video game developed by LucasArts, a television series produced for Fox in cooperation with Nelvana Limited, and a series of episodic adventure games developed by Telltale Games. In addition, a variety of machinima and a webcomic have been produced for ...
 
oh lol
 
Have you never played Sam and Max?
Please tell me you have at least heard of Guybrush Threepwood.
 
no :|
 
6:57 PM
no
 
7:09 PM
@TonyTheLion So you've never played Monkey Island?
 
Anyway, just found a review on a "new" Sam and Max game I wasn't aware of:
> This game makes me so happy I could puke rainbows.
@TonyTheLion Not the classic adventure gamer, are you?
 
I don't play games, and the rare times I do, I've got bored with it after a short while
 
hm... boost 1.49 - no new libraries. there was a lot of accepted libs and still nothing new
 
@TonyTheLion Get out! lol
 
7:11 PM
:P
 
OMG Sam and Max Season 1 is only 3,75 Euro at amazon?
 
@FredOverflow It didn't cost too much at release either. Makes sense to me, I do use Amazon.co.uk a lot, good deals.
@FredOverflow Is the new part to you the fact that it's a re-release of Season 1, or that there is a Season 1?
 
The new part to me is that there is anything after "Sam and Max hit the road" :)
@LucDanton Oh, it's twice as "expensive" at amazon.co.uk, but I want the English version, of course.
 
@FredOverflow I recommend all the new ones (that would be three seasons IIRC?), although I can't compare them to the original games since they were a bit before my time and I never played them.
If you're wondering the Monkey Island one is very good, too.
 
Isn't Sam & Max produced in Croatia? That's why it's so cheap.
 
7:38 PM
see comments
3
A: How to prevent an r-value

Seth CarnegieBesides @Xeo's answer, you can also do template<typename T = int> // thanks to Xeo for suggesting the default parameter void SetItem(Key&& key, const Value& value) { static_assert(sizeof(T) == 0, "SetItem cannot be used with temporary values as keys"); } This has the adva...

 
@JohannesSchaublitb Then what?
 
then please participate
 
quick C++11 question - after I do a std::move( p ), p will always be nullptr, right? (I've confirmed this with a quick test - makes sense, but I want to confirm that this is guaranteed...)
 
@kfmfe04 No, not true.
 
@LucDanton glad I checked - please explain
 
7:50 PM
std::move has a misleading name, it doesn't do much, and it certainly doesn't do a move -- that's what the move constructor does.
So if I have std::unique_ptr p = /* initialized */; std::move(p); then nothing happens.
 
interesting! but if there is a receiver, then p will become nullptr?
 
If I have std::unique_ptr p = /* ... */; auto moved = std::move(p); then yes, p == nullptr holds.
 
excellent! tyvm for the clarification - so it sounds like std::move() is actually a cheap operation
 
Is int _p and int p the same?
 
almost compiler based?
 
7:52 PM
yes
 
std::move(expr) is almost always equivalent to static_cast<T&&>(expr)
 
(I mean costs nothing during runtime, right?) -- ah... ...I guess it's yes - no cost, then
 
(The rest of the time it's equivalent to static_cast<T const&&>(expr) ;)
 
excellent - I'm going to most as much of my legacy code to std::unique_ptr and move semantics then
it should save me from memory headaches
 
@LucDanton when it is equivalent to the latter?
will move sometimes cause static_assert errors?
like forward does?
 
7:53 PM
Don't think so, it binds to everything.
 
@LucDanton sry to bother you - one more question - if I have a
std::unique_ptr<int> giveup() { return move(p); }
I can expect p to be nullptr, correct?
after a call, I mean, and assuming there is a receiver
 
I guess. It's usually better to not rely on a moved-from object to be in any particular state though.
 
I guess that's why people use shared_ptr's in place of unique_ptr...
 
(The reason I can't confirm with a straight 'yes' is that I don't want to account for a weird elision depending on the type of p, too.)
 
7:59 PM
hehehe - ic - tyvm for your help! 8^)
 
@kfmfe04 No, much the same holds for std::shared_ptr after a move.
 
@LucDanton so shared_ptr wouldn't help me too much either, in my case? I guess I may still have to check state...
 
I have no idea what you're doing so I can't comment on that. I'd say std::unique_ptr would be fine. However don't check for the state after a move.
 
anyhow, I will think carefully about my object lifetimes and how to manage these pointers correctly
ok - got it
 
std::unique_ptr p = /* ... */; /* use it */; something_involving_a_move(std::move(p)); /* don't assume any state for p */; p.reset(/* ... */); /* it's okay to reuse it! */
 
8:02 PM
excellent example of how I don't need to bother about the state - ty
 
In general the one operation you can do on a moved-from object is reassigning to a new state. Both operator= and reset achieve that for std::unique_ptr.
For a container, there's assign too for instance.
 
talking about containers, is there any disadvantage to using emplace_back() everywhere (in place of push_back()) for vectors?
emplace_back() seems to work regardless of whether or not T is an unique_ptr<> type
I'm guessing it has something to do, again, with copy semantics
 
@kfmfe04 You can't use list-init syntax, which really only matters for aggregates and is a matter of syntax, not semantics.
 
ic
 
So you can do v.push_back({ foo }); but not v.emplace_back({ foo }); (unless it's a container of std::initializer_list and foo has the right type).
For a non-aggregate that doesn't matter because you can switch to v.emplace_back(foo); most of the time or something close to that effect.
 
8:08 PM
ok - so I still need to invoke the right method for aggregate types - ty
 
emplace_back is so awesome...
 
gotta love perfect forwarding
whenever I go away from C++ for a few months, I miss the semantic richness of C++
it's nice to know a programmer's intentions just by looking at how parameters are passed
 
8:34 PM
Hello.
I need some help with a question. This one got flagged as very low quality.
0
Q: C++: Initialize boost array/multi_array

EagleI've defined boost::multi\_array with typedef boost::multi_array<unsigned int, 1> uint_1d_vec_t; typedef boost::multi_array<unsigned int, 2> uint_2d_vec_t; uint_1d_vec_t foo( boost::extents[ num_elements ] ); uint_2d_vec_t boo( boost::extents[ num_elements/2 ][ ...

Since I'm not a C++ guy I can't really judge.
 
Don't see anything obviously wrong with it.
Possibly a reference to the answers the OP made to him/herself? Not related to C++ though.
 
Oh?
It was tagged C++ by the OP. :/
 
I mean that the way he or she answered is not the preferred way, but that's not something that couldn't be fixed by someone that doesn't know C++ that much.
Also is it worth it to salvage a 2009 question, even though no answer is accepted?
 
Well, if people find it could be of use to others, yes otherwise no. I can't tell.
 

« first day (469 days earlier)      last day (4494 days later) »