« first day (746 days earlier)      last day (4219 days later) » 

10:00 PM
@StackedCrooked what, exactly, makes it so your counter-example prevents RVO from happening?
 
NRVO requires copy constructor though
or is that copy assignment? I dunno
 
I think it's the random?
b/c compiler can't tell what reference to optimize out of the method?
 
@Kache The destination location is different from its original location, so a copy must be made.
 
ah, ic
 
RVO means that the compiler will construct the return value at the location that the return value will be stored. E.g: int foo() { int result = 0; return result; } and then int n = foo(); // the result is created on the location where n is stored, so no copy is needed.
However, if two objects are created in the function scope and the compiler has no means to know which one will be returned, then it has to resort to copying the result.
It's explained on the Wikipedia page on RVO.
 
10:06 PM
yeah i was looking at that
lemme clarify then
is it the nature of the nested vectors, or the use of the rand()
nested vectors, where the source can't really be "moved" outside of the scope
or rand() b/c compiler can't determine until runtime
 
@Kache Actually, in my case RVO was never an option for the inner vectors because they are not allocated on the stack.
 
char *buffer = new char[size];
Should I delete this with "delete buffer;" or "delete [] buffer;"?
 
Ooh, now you've done it.
 
delete[] is the proper one but that doesn't mean you should use it
 
user142019
10:15 PM
@Alxandr you should delete it with std::string::~string.
 
@Zoidberg'-- I disagree, don't use std::string unless you're actually dealing with strings. Instead use vector<char>, or if you really cannot afford the space taken by 2-3 extra pointers, use unique_ptr<char[]>
 
user142019
Oh buffer, yeah.
 
@StackedCrooked I'm using a library that requires pointers
 
user142019
@Alxandr so?
 
user142019
std::vector<char> buffer;

stupid_library(buffer.data(), buffer.size);
 
user142019
10:18 PM
buffer.data() returns a pointer.
 
@Alxandr vector::data or unique_ptr::get return raw pointers
 
Hmm
 
@Alxandr Seriously, you don't ever need to use the "array" versions of new and delete. Use a vector instead.
 
The library (libspotify) has a method (sp_link_as_string) that requires a buffer to fill, can I use a vector for that?
 
user142019
Yes.
 
10:21 PM
std::vector<char> buffer(512); // voila a buffer of 512 bytes
 
user142019
std::vector<char> buffer(1024);

sp_link_as_string(buffer.data(), buffer.size());
 
Wow, that's nice :)
 
user142019
vector handles all clean-up for you.
 
user142019
I suggest one of these:
 
So I don't even need to delete it? I just let it go out of scope?
 
10:22 PM
Exactly. That's what deterministic destruction is all about.
 
user142019
1713
Q: The Definitive C++ Book Guide and List

grepsedawkThis question attempts to collect the few pearls among the dozens of bad C++ books that are released every year. Unlike many other programming languages, which are often picked up on the go from tutorials found on the Internet, few are able to quickly pick up C++ without studying a good C++ book...

 
user142019
And this one may also be very useful: en.wikibooks.org/wiki/C%2B%2B_Programming/RAII
 
user142019
@Alxandr Exactly, the destructor will be called when the vector goes out of scope.
 
Yeah, I know :)
Just one thing, what do I import to get the vector?
 
vector
#include <vector>
 
10:24 PM
Thanks a bunch :)
 
user142019
There is no valid reason in normal C++ code to ever use new except for writing a certain function that the Standard Library lacks for some reason.
 
@Zoidberg'-- ?
 
user142019
@Cheersandhth.-Alf make_unique.
 
well that would be library code
other examples for library code include, just about everything
your own immutable string, vector with uninitialized and transferable storage, u name it
 
user142019
I mean with “normal C++ code” code for normal applications, not stuff like kernels.
 
10:27 PM
it's all absent from the standard library
 
user142019
Your own immutable string, you can use std::unique_ptr for that.
 
user142019
And uninitialized storage, I don’t see how you can even do that with new, since new always calls the ctor.
 
well you can, if all you care about is the literal description
 
user142019
@Cheersandhth.-Alf why not?
 
10:28 PM
doesn't provide any of the advantages, and confers a host of disadvantages
 
@Zoidberg'-- operator new
 
user142019
And why can’t you use a vector?
 
of course you can
it's just clumsy and inefficient
 
user142019
It’s not inefficient until you measure.
 
well it is
let's say, for example
that you're calling the Windows API function GetCommandLineArgsvW
i think that was its name
 
user142019
10:30 PM
Y u no argc and argv.
 
the result is a vector, but that storage should be deallocated with LocalFree
 
user142019
GetCommandLineArgsvW returns std::vector?
 
user142019
Isn’t the WinAPI a C API?
 
@Zoidberg'-- because those are only for *nix programs and toy programs on other systems
@Zoidberg'-- u now, the term "vector" didn't originate with the C++ standard library
 
user142019
Wait
 
user142019
10:31 PM
In Windows you can’t use argc and argv?
 
so, a std::vector can be used, at the cost of copying the whole shit
 
user142019
I knew Windows was terrible, but this is just ridiculous.
 
and not just one time
 
user142019
Why copying? You can move it.
 
so, std::vector is inefficient for this real-world usage
 
10:32 PM
@Zoidberg'-- Never heard of WinMain?
 
because it lacks transferable storage, and lacks deleter functionality
 
user142019
@StackedCrooked nope.
 
user142019
Last time I programmed for Windows was six years ago.
 
@Zoidberg'-- not if you want to support non-English filenames, no
 
10:33 PM
@Zoidberg'-- the default WinMain entrypoint has a LPSTR instead of argv, but you can specify you want to use a regular main(int argc, char* argv[]) entrypoint as well.
 
hello all
see comments
 
user142019
@melak47 LOL
 
49
A: How to disallow temporaries in C++

ecatmurAnother macro-based solution: #define Foo class Foo The statement Foo("hi"); expands to class Foo("hi");, which is ill-formed; but Foo a("hi") expands to class Foo a("hi"), which is correct. This has the advantage that it is both source- and binary-compatible with existing (correct) code.

 
user142019
Windows is the worst OS ever.
 
@JohannesSchaub-litb were? were?
 
10:35 PM
@melak47 AFAIK, argc and argv do not work well for something.
 
user142019
If I’d program for Windows, I’d use Cygwin anyway.
 
Something about non-ASCII text.
 
@Cheersandhth.-Alf i -1ed it
 
@R.MartinhoFernandes I didn't mean to say they were. But you can use them, if you like :p
 
@Zoidberg'-- That's because you prefer terrible stuff built on terrible stuff. Or maybe you're just silly.
 
user142019
10:36 PM
No, I prefer portable code.
 
user142019
And WinMain isn’t portable since a program must have exactly one main function called main.
 
user142019
So you’ll need both and that is terrible since you have two entry points.
 
@Zoidberg'-- lol
You sound a bit short-sighted.
 
@JohannesSchaub-litb k me 2
 
user142019
Whatever. I don’t program for inferior platforms anyway.
 
user142019
10:38 PM
POSIX <3
 
@Zoidberg'-- just use a standard main (with no arguments) and be done with it.
well except for MFC
 
@Zoidberg'-- Bring on the OS cleansing
 
@Zoidberg'-- Oh, we were just bashing POSIX on ##C++ @ Freenode :D
 
how was that about invocation of operator void() for use of object as full-expression?
i think it was just idea that andrew koenig had
 
TIL about #line
 
10:43 PM
hm my operator void() isn't called even with explicit conversion to void
 
Dammit.
 
@Cheersandhth.-Alf the spec says it shall not be called
 
it's called with g++ 4.7
 
same for a conversion to a base class or to the same class
 
10:44 PM
:-)
 
@Cheersandhth.-Alf it's a GCC bug
 
@Cheersandhth.-Alf i made a quiz question a while back
11
Q: How to avoid "(void)a" cast causing side-effects?

Johannes Schaub - litbI have this code and GCC prints "what!?". How can I avoid that, so that the void cast simply has the C meaning "Ignore the lonely 'a;'"? #include <iostream> struct A { template<typename T> operator T() { std::cout << "what!?"; } }; int main() { A a; (void)a; }

 
Man
windows command line limits the line size to 4096
this really sucks donkey cocks
 
10:47 PM
use xargs
 
I'm pasting data from the web to stdin
 
@JohannesSchaub-litb pipes in windows suffer from incompatibility between byte unit and default UTF-16 encoding of text
@kbok it's increased since then (way back then). where do you get that number?
 
@Cheersandhth.-Alf I paste a large string, it truncates at this size.
 
"maximum length of this string is 32,768 characters, including the Unicode terminating null character"
From CreateProcess docs
 
maybe it's the console app which sucks
or PS
 
10:52 PM
hmm
 
or maybe [cmd.exe] or [powershell.exe] or whatever shell you're using
 
That's powershell (what I call PS)
 
posted on October 31, 2012 by Eric Battalio

C++ is alive at Build 2012! Developers have been filling the C++ sessions and getting tips, tricks, insights and example code from the experts. But you don't have to take our word -- sessions from Tuesday are available online: Bringing Existing C++ Code to Windows Store Apps. The Power of C++ - Project Austin App. Connecting C++ Apps to the Cloud via Casablanca Developing a Windows Store app

 
user142019
Use Z shell and a decent terminal emulator.
 
@Cheersandhth.-Alf don't you have to use wmain to get that limit?
 
11:02 PM
@Praetorian it has nothing to do with C or C++ startup function. it works for Pascal, Fortran, Cobol, even Python i'd guess ;-)
 
Hmm, ok
 
0
A: How to disallow temporaries in C++

Cheers and hth. - AlfSimply don't have a default constructor, and do require a reference to an instance in every constructor. #include <iostream> using namespace std; enum SelfRef { selfRef }; struct S { S( SelfRef, S const & ) {} }; int main() { S a( selfRef, a ); }

 
user142019
@Cheersandhth.-Alf what about template<std::size_t N> T(char (&&)[N]) = delete;, or whatever the syntax is?
 
user142019
Or can’t you have an rvalue-reference to a C-style array?
 
Xeo
char (&&)[N]
 
user142019
11:05 PM
lol dat syntax
 
user142019
template<class U>
T(U&&) = delete;
 
@Zoidberg'-- hm, me not understand, passing to johannes. i'm going to have some tea
 
user142019
oohh wait nvm
 
Let the war begin.
 
user142019
11:07 PM
Weird question, anyway.
 
Strong and weak typing are not well defined concepts.
 
@EtiennedeMartel lol
 
user142019
Does C# convert between floats and ints?
 
hi
 
Read the article (and, if you liked it, star that, because I'm a slut)
 
11:08 PM
Can I negative star it?
 
@Cheersandhth.-Alf added an answer
0
A: How to disallow temporaries in C++

Johannes Schaub - litbThis one doesn't result in a compiler error, but a runtime error. Instead of measuring a wrong time, you get an exception which may be acceptable too. Any constructor you want to guard needs a default argument on which guard(this) is called. class Foo; struct TemporaryGuard { TemporaryGuard(...

 
Hihi @EtiennedeMartel is a slut.
 
user142019
@JohannesSchaub-litb eeewww a throwing dtor. :P
 
@Cheersandhth.-Alf nice idea with the self ref xD
 
@Zoidberg'-- The leaders of the church often turn out to be the biggest perverts of them all don't they?
 
user142019
11:11 PM
TIL: litb is the pope.
 
@Zoidberg'-- It implicitly converts from int to double because it's safe.
 
user142019
#define MAKE_FOO(arg) Foo _myfoo(arg)
 
user142019
And use MAKE_FOO everywhere instead of Foo. :)
 
user142019
Implicit conversions complicate all the things!
 
Xeo
Nice idea, but as soon as you have one variable: S(selfRef, a);. :/ — Xeo 13 secs ago
 
11:17 PM
@Zoidberg'-- Indeed. Still, int -> double is a widening conversion.
 
user142019
using MakeSureNotToMakeThisATemporaryFoo = Foo;
// Problemo solvo.
 
@EtiennedeMartel Maybe -- but then again, if you have a 64-bit int and a 64-bit double, it may not be either.
 
user142019
@Xeo S(SelfRef, S const& s) { assert(&s == this); }, if a runtime error is acceptable. — Zoidberg'-- 44 secs ago
 
Xeo
S&& a = S(selfRef, a);!!
 
@JerryCoffin int is an alias for System.Int32 in C#.
 
user142019
11:21 PM
@Xeo If you’re going to do that, you’re already realizing you are trying to make a temporary, which you shouldn’t do.
 
@EtiennedeMartel and string an alias for System.String?
 
obvious C# just wants typedef.
 
@Borgleader Yes.
 
user142019
@Xeo S(SelfRef, S&& s) = delete;
 
@EtiennedeMartel Ah, didn't catch the context that the discussion was specific to current implementations of C#.
 
Xeo
11:23 PM
@Zoidberg'-- a is an lvalue
 
user142019
Oh right.
 
Idle curiosity: Looking at stackoverflow.com/q/9249781/439902 , if you are not to throw from a move constructor, why does the standard permit it?
 
@DeadMG Yeah, typedef would be fun to have. We only have a file-level half assed using statement right now for that purpose.
 
user142019
@Cheersandhth.-Alf what is SelfRef for, anyway?
 
@nixeagle The Standard allows a lot of stuff which is a very stupid idea.
 
11:27 PM
@DeadMG sure, some of it is due to backwards compat and so on. I was mostly curious what use case they had where allowing move constructors to throw was a good thing?
 
@Zoidberg'-- for one, it distinguishes the self ref constructor from a copy constructor. it's also about readability, showing a reader of the code that the self ref is intentional.
 
user142019
Oh yeah copy ctor.
 
user142019
You can also enforce two-phase initialization like a motherfucker. :P
 
user142019
And it will work, since temporaries don’t bind to non-const references.
 
11:30 PM
@Zoidberg'-- Spoken like a first-rate C++ programmer.
 
user142019
What does first-rate mean?
 
excellent
 
user142019
Oh. xD
 
user142019
Well, I’m a terrible C++ programmer.
 
first-rate |ˈˌfərst ˈˌreɪt|
adjective
of the best class or quality; excellent: first-rate musicians.
• in good health or condition; very well: I think you look first-rate.
 
user142019
11:31 PM
Y u monospace font.
 
@nixeagle I doubt it's that anybody ever thought it was a good thing in itself, but that some designs that are otherwise good might include it as a corner case (e.g., Howard pointed to one in a comment).
 
user142019
Wtf.
 
@Zoidberg'-- It has an Instagram-like effect if I do that.
 
user142019
That guy who flagged must have been the pope or some other religious freak.
 
11:31 PM
^ "Plans to monitor all Britons' online activity are needed to help society fight crime and "save lives", Home Secretary Theresa May has said.

Under draft plans, service providers will have to store details of all internet use in the UK for a year."
 
user142019
@StackedCrooked Hipsters gonna hipster.
 
pointless
hasn't she ever heard of "Encryption"?
 
@Cheersandhth.-Alf Reminds me of that: fullcomment.nationalpost.com/2012/02/14/…
 
user142019
in C#, 24 secs ago, by Zoidberg'--
Stop flagging, it’s annoying to all 10k people on the entire chat.
 
I didn't see it
 
user142019
11:34 PM
The pope flagged it because it was about condoms.
 
why flag condoms?
 
@jerry Yea I was kinda curious what the corner case actually was.
 
user142019
@JohannesSchaub-litb because sex is for getting children, not for pleasure. :P
 
user142019
I wonder if the pope is on /b/.
 
11:37 PM
Another idle curiosity thing, is there a reason why compilers can't statically check noexcept? Even as some sort of compiler extension in gcc/clang or whatever?
I know the standard says...
 
user142019
> I'm just trying to imagine a creepier combination of 3 things
 
user142019
> PHP, Java and Visual Basic.
 
They say that in case of doubt it's better to use parentheses to ensure the intended operator precedence. But if you always do that, isn't that a little sloppy?
 
@nixeagle It looks to me like he was pointing to something like a linked list using a sentinel instead of a null pointer to signal the end of the list. When you create the new list from the existing data, you allocate a new sentinel node for the old list, so it's now an empty list that still satisfies the type's requirements. Allocating the new node could throw, in which case the move ctor can't fulfill its obligation, and has to throw as well.
 
@JerryCoffin ah! That kinda makes sense.
 
Ell
11:43 PM
hi guys
 
user142019
hi
 
MSVC does not support noexcept :(, here we go with compiler specific defines x)
 
user142019
The support for noexcept is exceptionally low.
 
user142019
lol
 
11:50 PM
zoidberg, gcc supports it.
 
user142019
Clang supports it too.
 
@Zoidberg'-- Those grizzled veterans, writing C++ when it meant something! None of this coddling that that nullptr and lambdas give you! No, we had to write our code uphill both ways!
 
clang supports prettymuch everything gcc does these days no?
 
@Code-Guru Oh, tits!
 
@EtiennedeMartel heh
 
user142019
11:52 PM
@nixeagle I have no idea. See clang.llvm.org/cxx_status.html.
 
#define nullptr 0, language feature added! Really, I'm not very sure what makes it any different from NULL :).
 
It's of type nullptr_t
 
Ell
it doesn't implicitly convert to 0 does it?
 
Ell, probably not.
 
user142019
@Ell no.
 
user142019
11:53 PM
It implicitly converts to T*.
 
user142019
And explicitly to bool, if I’m right.
 
Ell
what is the _t on everything? is it type?
 
yes
 
user142019
@Ell no, it means “testicle”.
 
Ell
I don't see the point in it o.O
 
11:55 PM
Ell, I think just convention.
 
Ell
why doesn't everything have it? why isn't it std::string_t?
 
user142019
@Ell foo_t foo;.
 
As to not pollute the namespace further
 
user142019
@Ell std::string is in a namespace.
 
Ell
foo foo;
 
11:56 PM
C didn't have namespaces, so having a slightly quirky way of denoting types was good
 
user142019
And the Standard Library doesn’t use capital letters for anything besides std::ios_base::Init, IIRC.
 
@Zoidberg'-- Pretty sure you're right
 
which is why we have size_t, since it is in the global namespace as well as a copy in std.
 
Can you initialize class members in VS2012?
 
That actually makes sense, nice question Ell. Now I know it is not arbitrary :)
 
user142019
11:57 PM
Hmm. Stranger on Omegle. Joined Facebook an hour ago.
 
@Rapptz, just tried. No
 
lol.
 
huh?
 
@nixeagle Thanks. That sucks.
 
user142019
 
Ell
11:58 PM
lol :L
 
@Zoidberg'-- You're not sure?
 
user142019
@Collin no.
 
I'm going with pervert
 
@Rapptz, that is one of the things I can't #define away like the noexcept stuff. :/
/me is trying to port...
 
user142019
@Collin me too.
 
11:59 PM
I want to write something using C++11 features but VS2012 is kind of annoying since it's behind.
 

« first day (746 days earlier)      last day (4219 days later) »