« first day (321 days earlier)      last day (2523 days later) » 

user1593881
1:50 AM
Apparently this functions on GCC without including the <string> header and fails in VS 2013. What's the magic behind the <fstream> (implementation?) when using the two compilers?
 
perfectly legal
it just happens that you get a definition "for free" in GCC, but not in VS2013
both implementations are conformant
makes writing standard compliant code "fun"
 
user1593881
I see. Wasn't aware of that.
 
the definition for std::ostream& operator<<(std::ostream&, const std::string&) is supposed to be accessible if you #include <string>, but nobody said that a header can't be included by another, implicitly
my usual routine is to compile my libraries and programs which are supposed to be portable with VS, MinGW's GCC, GCC on Linux, and Clang
tracking buggy standard features on different impls is "fun"
 
user1593881
Yes, fun is the right word.
 
user1593881
Appreciate.
 
user1593881
2:03 AM
@milleniumbug Would you say that if one is to work with strings one should include the <string> header and not rely on these fun free rides?
 
yes, don't rely on free rides
 
2:44 AM
@RawN there's an obscure technicality that requires that the definition of the class std::string is provided by <fstream>, but <string> has lots of things that aren't members of that class (operator<< you discovered, comparison operators, getline, etc), so indeed include <string> if you use strings.
 
user1593881
3:09 AM
Thanks all. Will do.
 
3:25 AM
@milleniumbug Actually, the standard gives explicit permission for any standard header to include any or all others as it sees fit. Early implementations made much more use of this permission than current ones, as a rule.
 
 
2 hours later…
5:10 AM
If the code(C++ syntax) introduce names in local & namespace scope but not in class scope, irrespective of following OOP/functional paradigm. Is it not considered C++ code?
 
SBM
Hello
 
5:36 AM
@overexchange Considered by whom? What difference does it make whether somebody considers it C++ code or not?
 
5:57 AM
@JerryCoffin I just got the chance to see style guide here, which says, use struct instead of class, if there is no necessity to maintain invariants. Considered by whom? Considered by contributors/author of C++ who introduced this language, with a reason for each language construct.
 
6:15 AM
@overexchange There's a big difference (in my mind) between "is this C++?" and "is this well-written C++?"
 
style guide says, The guidelines are focused on relatively higher-level issues, such as interfaces, resource management, memory management, and concurrency. Such rules affect application architecture and library design. Following the rules .... statically type-safe, has no resource leaks, and catches many more programming logic errors than is common in code today. And it will run fast -- you can afford to do things right. Following style guide, does not imply to well-written C++ code?
 
@overexchange By itself, no, probably not. It is generally good advice though. But your earlier question was about "Is it not considered C++ code?", not "is this advisable?"
 
For example, For any python code, we use terms like, code is Pythonic or not pythonic. Am not sure, the terms used accordingly in C++ world. Question was, if names in class scope are not introduced, then is it considered Cplusplusic code? weird term used...
 
@overexchange Defining a name at class scope can be perfectly fine C++, if the name make sense within the scope defined by that class.
 
if the name make sense within the scope defined by that class? Am not clear, when you said, make sense. Anyways, style guide answered my question
names in global scope is anyways avoided
 
SBM
6:58 AM
Oh
 
 
15 hours later…
9:35 PM
I am writing an API. I am implementing a member function that returns the name of an object. The problem is, that the object doesn't have to have a name.

There are several way I could implement this function. I am thinking about `std::optional<const char *> name() const` vs `std::optional<std::string> name() const`. Which of these is better? Do you have another idea how to implement this?
I am writing an API. I am implementing a member function that returns the name of an object. The problem is, that the object doesn't have to have a name.

There are several way I could implement this function. I am thinking about `std::optional<const char *> name() const` vs `std::optional<std::string> name() const`. Which of these is better? Do you have another idea how to implement this?
 
nwp
@andrew Maybe you could give all nameless objects the name "" and save yourself from the optional stuff.
 
9:51 PM
@nwp Empty names can be a possible value. I want to differentiate between objects with empty names and no names.
@nwp Thanks for the hint to this room btw :)
 
@andrew std::optional<std::string>
Sep 11 '16 at 12:21, by milleniumbug
No one likes C strings
 
@milleniumbug A reason for std::optional<const char *> name() const is that just compiles to a const char * that can be nullptr. Is this advantage so insignificant?
 
that's not true
nullopt, nullptr and a non-null value of const char* are all valid values of type std::optional<const char*>
in other words, you now have two null values (lol)
or, in yet other words, std::nullopt and (const char*)nullptr are separate entities as far as std::optional is concerned
 
10:07 PM
@milleniumbug I looked it up and you'r right. But I am pretty sure that I read this somewhere in the internet. Maybe this was the intial idea of optional?
 
nah
the idea is to have optional values for any T
since nullptr is a valid value for T*, you need provide another one
 
@milleniumbug yes and no. nullptr should indicate that it points to no object. if optional would do it this way, it would make sense i guess
 
special casing for pointers would be fucking retarded silly
given that a T type can store N values, std::optional<T> can store N+1 values
template<typename T> void f(T x) { boost::optional<T> y = x; } expects that y has a value
and that it always works
if this is too abstract, let's have another example
let's say you connect to a SQL database and return a value from it
these values are nullable unless you declare them NOT NULL
so you map aNullableColumn INT to std::optional<int>, and aNonNullableColumn INT NOT NULL to int in your C++ code
then you write some C++ code that returns a specific column for a given record for some id
but the record can be missing
so you need to distinguish between a missing record, an existing record with a null value for int, and an existing record with a "valid", not null value of int
so you write a std::optional<std::optional<int>>
it all works because there's no special casing
 
10:27 PM
1 message moved from bin
@andrew who owns the strings, where do they originate from? Is sequence equality identity? In absense of that, always prefer std::string because it sidesteps all those questions (and if object identity was an issue for the name itself, you'd have known )
 
now, have you had decided that std::optional<std::optional<T>> makes no sense because "it's supposed to point that it stores no object", you wouldn't be able to write this, instead you would have to write silly workarounds
 
You spend way to much energy here :) People who can't appreciate the value of generic code, won't appreciate this
@milleniumbug I think there was a proposal for an "intrusive_optional<>" of sorts in boost.
 
I mean, sure, you can introduce such special-casing optional (and I could probably find an application for it), with all of its caveats, but it would be less useful than the alternative
 
@milleniumbug good example
@sehe Oh I forgot about the ownership. It makes a lot of sense to just copy it into a string so that I have no problems with that.
 

« first day (321 days earlier)      last day (2523 days later) »