« first day (481 days earlier)      last day (4476 days later) » 

5:09 PM
1
A: How do effectively use the string data_type in C++?

R. Martinho FernandesForget about pointers. string *cPtrI = &a; string *cPtrJ = &exceptions; // ... if(cPtrI[i] == cPtrJ[j]){ //if index of A equal index of J then cPtrI[i] is the same as *(cPtrI + i), which would be indexing into an array of string. That's why cPtrI[i] == 'a' doesn't compile. cPtrI[i] ...

 
0
Q: Is conversion allowed with std::vector's template constructor taking iterators?

Alexey KukanovIn the C++11 standard, Section 23.3.6.2 [vector.cons], the following is said: template <class InputIterator> vector(InputIterator first, InputIterator last, const Allocator& = Allocator()); 9 Effects: Constructs a vector equal to the range [first,last), using ...

 
ARggh, I need help. I can't seem to explain the difference between std::string* and char*.
 
user142019
Say that std::string* is a pointer to an std::string and char* is a pointer to a char.
 
Did that already.
Twice.
 
user142019
Say that std::string is a container and that char is just a single character.
 
user142019
5:11 PM
Hi Greg.
 
@RMartinhoFernandes Just wait a while, Tomalak's in there, he'll yell some sense into the OP
 
@Prætorian To be honest, that sounds exactly like what the OP needs. I have exhausted the number of different ways I can explain this.
 
@RMartinhoFernandes I think the OP is confused over the difference between a cstring and a std::string. He's trying to treat the std::string like a cstring. (I'm speculating)
 
@MooingDuck Yes, I think he's stuck in a C mindset where everything non-trivial is a damn pointer.
 
@MooingDuck That is exactly what the problem is
 
5:21 PM
@RMartinhoFernandes Have you mentioned that std::string and cstrings are completely different in every way, and should be treated as such?
 
No. But now I'm... let's say busy.
I give up.
 
@Gabe A game.
With semaphores.
Also, you lose the metagame of obscure, far-fetched references.
 
5:35 PM
@CatPlusPlus That makes me think of this xkcdb quote: xkcdb.com/?7620
 
5:46 PM
I'm thinking this has UB in it ideone.com/F0C4j
correct?
 
* sizeof(char) is not necessary, sizeof(char) is defined to be 1.
Also, the comment in line 5 makes no sense. strcpy does append a NUL character.
Of course, lines 12 and 13 should be const char*, and so should the parameters be.
Apart from that, I see no problems for a C program. This is a C program, right?
 
Also, I'm surprised it complies without #include <string.h>
 
Oh, you forgot free(res); at the end of main.
@Prætorian C is very forgiving when it comes to forgetting includes ;)
 
@FredOverflow you mean free(res);; it is a C program after all :)
 
Remember, it's possible to call undeclared functions in C, but not in C++.
 
5:53 PM
@FredOverflow yeah but doesn't it assume the function signature to be int foo(void)? Maybe that's why it's segv'ing
 
@TonyTheLion Where do you think the UB comes from? Maybe I'm overlooking something.
 
@FredOverflow null termination chars copied by strcpy in the first string, and then writing past that in the second?
 
@Prætorian No, it assumes to function signature int foo() without the void, so you can pass as many arguments as you want.
 
@FredOverflow yep
 
@TonyTheLion No, buf has enough space for both strings and the NUL terminator.
 
5:54 PM
ah ok
 
Just in case it's not clear, strpy(a, b); means copy b into a, not the other way around.
 
I'm never sure about the NULL termination chars, and whether strlen includes it
@FredOverflow yes I know that
 
strlen does not include the NUL terminator.
 
ideone.com/y5m57 compiles, looks like it was the missing includes
 
Note that there is only one L in NUL. The pointer NULL is a completely different thing.
 
5:56 PM
ah ok
 
NUL is of type char, whereas NULL is of type void*
 
@FredOverflow That's very dangerous though.
 
@RMartinhoFernandes Of course it is, but it explains why the compiler accepts the program even without the include.
I've had very nasty bugs thanks to implicit function declarations.
 
It should be law that if any Microsoft employee writes an MSDN article without referencing needed namespaces, they should be shot!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
@Prætorian It's not segfaulting.
 
5:59 PM
@Xaade That would be a little inhumane I think.
 
@Prætorian Still missing stdio.h.
 
@RMartinhoFernandes haha, of course it is, still printed and exited happily though
 
@Xaade But inhumanity is what makes the world go round ;)
 
Well it's ridiculous notion that somehow I'd know how to navigate their redundant namespaces to find some type that they've written about in an article. The namespace isn't even on the main article..... WTF
 
C does not have implicit return from main.
You have UB right there.
 
6:01 PM
@RMartinhoFernandes C89 is a bit old ya know.
 
@LucDanton They're not compiling as C99.
 
@Xaade What namespaces besides std are you talking about?
 
(And I didn't know they added that.)
 
@RMartinhoFernandes Of course, all the cool cats are using C11. Why live in the past?
 
@LucDanton They're not compiling as C11 either!
 
6:03 PM
I watched Chandler's talk today. It sounds incredibly promising.
Also during the panel at the end of the second day, when he mentioned that they were soon going to release a refactoring tool for C++, Herb and Stroustrup nearly literally dropped their jaws.
 
@FredOverflow Nah.... WPF stuff. Trying to figure out how to catch an unhandled exception on a worker thread and dispatch to main UI thread.
 
C (gcc-4.3.4) means C89 (ok, maybe GNU C 89).
 
@StackedCrooked Because C++ and Agile usually don't go well together. Let's see if that really changes.
 
He claims it was designed to do automatic refactoring of the entire Google codebase. It even refactored macros. That sounds pretty impressive.
But I guess you're right that perhaps I shouldn't get my hopes up too high before actually witnessing its possibilities myself.
 
$ cat a.c
int main() {}
$ gcc -std=c89 a.c
$ ./a.out || echo "doesn't return success from main"
doesn't return success from main
$
That's what was happening on @Tony's program.
Somehow @Prætorian's was returning success from main.
 
6:17 PM
Hmm, found a bug in chrome. If I open and immediately save a 10M pdf to a flashdrive, chrome freezes until the save is complete. (About 30s)
 
@RMartinhoFernandes different versions of gcc maybe?
 
@Prætorian No, just UB.
 
6:39 PM
§ 23.2.3/3 [sequence.reqmts] requires that the iterators for the vector(iterator, iterator) constructor refer to elements implicitly convertible to value_type. But § 23.3.6.2/8 [vector.cons] says "Complexity: Makes only N calls to the copy constructor of T". Is this a mis-wording in the standard?
 
Elements are converted to T and then copied into the vector.
 
@RMartinhoFernandes that makes no sense. Aside from the obvious performance penalty, I'm having trouble thinking of how one would easily code that.
 
@MooingDuck Er, new(ptr) T(*it)?
 
@RMartinhoFernandes that doesn't use the copy constructor if *it is not T. Standard impl;ies it should.
 
@MooingDuck struct foo { operator T(); } ;
 
6:45 PM
@RMartinhoFernandes for std::vector<std::string> and char** as the iterator, you're code doesn't use the copy constructor. Implies that char** is not a valid iterator for std::vector<std::string>'s constructor.
 
@MooingDuck if *it is not of type T a temporary will be constructed as long as T has a non-explicit constructor that takes an argument of type *it; then the copy constructor is invoked
 
As-if rule?
Anyway.
T const& t = *it; new(ptr) T(t);
 
@RMartinhoFernandes I think as-if only applies to implimentation, not what code is UB.
@RMartinhoFernandes that does two copies if *it is a T, also not allowed by spec
best I have is const T& t = *it; new(ptr) T(t);, but it seems like a silly requirement
 
Damn, I have to download the spec again.
 
@Prætorian no, that is not right. if T is std::string, and *it is char*, then T(*it) will not invoke the copy constructor.
@RMartinhoFernandes I have it saved in my code folder
 
6:49 PM
@MooingDuck My disk died.
 
@RMartinhoFernandes what? no backups? Shame!
 
Of the C++ spec?
Why would I back that up?
 
Xeo
@Mooing: It seems the current wording indeed indicates that only a copy ctor may be called, but that was never intended. See open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#535
 
Fear of complete Internet breakdown?
 
@RMartinhoFernandes I just habitually back up my user folders
 
6:52 PM
Well, it's official, our student association goes on strike on March 22. Woo!
 
@Xeo oh good. How come that didn't get into the standard? It was proposed 6 years before.
 
> Complexity requirements specified in the library clauses are upper bounds, and implementations that provide better complexity guarantees satisfy the requirements.
§17.5.1.4, paragraph 7.
 
Xeo
Yep, may make 0 calls to copy ctor, but at most N
 
@Xeo that was what I had before, but I wasn't sure. It seems like cheating that they say "AT MOST YOU CAN DO 3 N" and but we use M instead. It's very similar to avoiding complexity requirements (even though in this case I know it's not)
 
Reminds me of Alexandrescu's uninitialized_fill implementation: `new(&*++it) T()`
(Or something like that...)
 
Xeo
7:00 PM
uninitialized_fill, you mean
 
I guess.
 
Xeo
Hm. I wonder if you could get short-curcuit evaluation with overloaded operator|| and operator&& somehow.
 
Never thought of that. Should be possible given that we are always told to make our types behave as built-in types.
 
Needs language support, or some Boost.Lambda-like magic placeholder.
 
@StackedCrooked we normally do so by not overloading operator|| and operator&&
 
7:05 PM
#define LAZY(...) ([]{ return (__VA_ARGS__); })
x || LAZY(f(y))
 
@RMartinhoFernandes clever. Not an overloaded ||, but I think that's step 1.
 
// Isn't this what you want?
bool Obj::operator||(const Obj & lhs, const Obj & rhs) {
    return lhs || rhs; // rhs.operator bool() not evaluated if lhs.operator bool() evalutes to true.
}
 
@StackedCrooked The parameter is already evaluated by that time.
 
@StackedCrooked Overloading || and && breaks short-circuiting.
 
@StackedCrooked Obj a = ????; bool result = a || Obj(expr_with_effects);
 
7:08 PM
Ah, I see.
 
Xeo
This is an example of an awesome SO question: stackoverflow.com/q/4275602/500104
Answers from both authors :D
 
@Xeo neat!
 
Nice little competition there.
 
Xeo
@RMartinhoFernandes Lazy evaluation is really not promoted in C++. :/
 
sbi
7:11 PM
Modules paper presentation by Daveed Vandevoorde. I really want this, but it's a tricky area... http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3347.pdf #cpp #wg21
 
Xeo
Yay, modules
 
nice
part of me finds it really hard to believe that the modules thing has gotten so far
 
Xeo
I already read that and that was basically what promted my question at GN :)
 
you'd think it was the kind of "crazy talk" that'd get shot down instantly in a committee
 
sbi
@Xeo Hey, we're talking a proposal here. And one that's just been named as "tricky". Beware!
 
7:12 PM
@jalf how can they shoot it down, they don't know what it is!
 
Who cares about proposals. Gimme an implementation.
There'll be at least 10 revisions of that paper more anyway.
 
@Xeo It wouldn't be that complicated. What D has is simply automatic lambdification of arguments.
 
"Compiler is busy thunking about your code."
 
I have a constructor which accepts a const std::wstring& str and passing a wstring to it, doesn't seem to pass it on to the member variable
strange
 
And yet the strangest part is wstring.
 
7:20 PM
Perhaps another constructor overload is being called than the one you're looking at.
Indeed, yet another reason not to use std::wstring...
It doesn't work with members :)
 
It's pretty useless.
Like wchar_t.
It might be useful if you're doing a lot of WinAPI calls, I guess.
I honestly have yet to see wchar_t used somewhere else.
 
It's convenient when working with WinAPI Unicode. Never, used it for anything else.
And even then the usage of std::wstring is a just-in-time thing. All my interfaces and members use UTF8 encoded std::string.
 
std::string sucks, too.
I'm tempted to attempt to implement strings my way. I'll never finish this, obviously, but still.
 
@sbi that standard complicates parallel compilation, and could conceivably slow compilation times.
@CatPlusPlus std::vector + a unicode library
 
I want unicode_string and byte_string to be two different things.
 
7:26 PM
I never really encountered problems with using std::string in practice.
 
@StackedCrooked linewrap
 
linewarp?
 
@MooingDuck Well, vector is good for buffer, but I don't want my string to be called "vector".
 
@CatPlusPlus strong typedef
 
Exposing implementation details.
 
7:28 PM
Perhaps string should be a concept.
 
Xeo
@CatPlusPlus template<class T, class Alloc> using string = std::vector<T,Alloc>;
 
@StackedCrooked two consecutive valid code-points might be codependent, and figuring out where it's safe to insert a newline is.... nontrivial
 
That's interchangeable with vector<T>, isn't it?
 
Xeo
Yeah
 
We have supposedly rich type system, let's encode some semantics in the types, eh?
 
7:29 PM
@Xeo #define alias using I suppose.
 
Xeo
@MooingDuck Why does it complicate parallel compilation?
 
What is a code-point?
 
Xeo
@RMartinhoFernandes Gnaaah
 
@StackedCrooked It's a thing.
 
@Xeo it requires some cpp files to be parsed before others in the same project. Current C++ can compile each TU simultaniously. (until link-stage)
 
7:30 PM
In character encoding terminology, a code point or code position is any of the numerical values that make up the code space (or code page). For example, ASCII comprises 128 code points in the range 0hex to 7Fhex, Extended ASCII comprises 256 code points in the range 0hex to FFhex, and Unicode comprises 1,114,112 code points in the range 0hex to 10FFFFhex. The Unicode code space is divided into seventeen planes (the basic multilingual plane, and 16 supplementary planes), each with 65,536 (= 216) code points. Thus the total size of the Unicode code space is 17 × 65,536 =...
@MooingDuck Ok, I understand the problem now. Isn't it inherent to multi-byte encoding?
 
@MooingDuck And yet, it doesn't help for compilation speed whatsoever.
 
@StackedCrooked nope, UTF32 has the same issue
@StackedCrooked A codepoint isn't a byte, it's a unicode value.
 
@MooingDuck Combining characters? But that's just skip ahead of 1.
 
I mean where a character is made up of more than one char_type instance.
 
Xeo
@MooingDuck I want parallelized linking. :|
 
7:31 PM
@StackedCrooked For instance, "..." is three characters. It's also three code points. It's also wrong to put a newline between them
 
We have ellipsis character for that.
 
@CatPlusPlus I don't know more than the name, and not to assume one codepoint<->one glyph.
 
@MooingDuck Should std::string take care of this? Isn't that a higher-layer responsibility?
 
Xeo
And it seems the llvm guys are up to something regarding that
 
@StackedCrooked that's what the C++ standard decided
 
7:33 PM
Not breaking up ellipsis is English language semantics, not related to encoding.
 
Stuff like this must be hellish to get right.
 
@CatPlusPlus we do, but it's the closest I have to an example that everone understand
@StackedCrooked that's why we have big libraries for it, and few programming languages bother
 
I don't recall multi-glyph codepoints.
 
@CatPlusPlus There aren't, but there's the combining characters
 
@MooingDuck Read all of it. It has a contingency to support module interfaces without implementations (i.e. basically headers).
 
7:34 PM
I don't think TrueType/OpenType supports that.
Combining characters are separate codepoints.
So it is one codepoint == one glyph.
It's just handled differently by layout engine, not related to string representation.
 
@CatPlusPlus either way, it's wrong to seperate them with a newline
 
Yes, but it's easy to see where they end.
 
Herb (re ObjC): "I'm flabbergasted that there's a language with a worse header problem than us!" :) #cpp #wg21
while(is_combining(*it)) ++it;
 
@RMartinhoFernandes I'll keep reading
 
Xeo
@RMartinhoFernandes Atleast they have partial classes. :/
 
7:39 PM
Obj-C is so damn obscure.
 
// in myclass/part2.hpp
#include <myclass/part1.hpp>

    public:
        virtual void f() = 0;
        virtual void g() = 0;

#include <myclass/part3.hpp>
@Xeo Tada!
No, I'm not serious.
 
Xeo
lol'd
 
@CatPlusPlus You're using Obj-C?
 
No.
I wouldn't touch that even for lots and lots of money.
 
Xeo
> [20:40:27] <david_chisnall> IRC needs a metaquestion optimisation pass.
 
7:40 PM
What if you had a ten-foot pole?
 
Xeo
I feel we need that here too
 
I wouldn't touch that with ten-foot pole held with two finglongers.
 
aaah, so that's what would have happened if I had invented the double finglonger
 
also good morning, people of a lesser mind
 
7:42 PM
Btw, I believe it's finger-longer.
 
perhaps thats the translation
 
Translation of what?
 
You're crazy.
 
Futurama
but it's most definitely called a finglonger
 
7:43 PM
I never watched Futurama translated.
 
@RMartinhoFernandes صبح بخیر، از ذهن کمتر
 
You're calling my hearing into question?
Doug Gregor's very simple module approach is getting a lot of interest. Bjarne: "I'm excited!" #cpp #wg21
What's he talking about?
 
Xeo
I'm seriously amazed about just how much stuff can blow up in China..
@RMartinhoFernandes Dunno, there's nothing on the pre-Kona papers list
 
@Xeo Why is there a "China Menaced by Exploding Monitor", "China Menaced by Exploding Sewer", "China Menaced by Exploding Toilet", and "China Menaced by Exploding Watermelons" at the end of that?
What doesn't explode in China?
 
Xeo
@RMartinhoFernandes That's the question
@RMartinhoFernandes Links to other articles?
> “You can only look forward to hearing what will explode next, can’t you?”
 
7:50 PM
I'm not clicking.
 
Xeo
And it's really, just that.
I like the comment thread on the coin one, though.
> China's booming economy has hidden meanings XD
 
> Filesystem Library for C++11/TR2 (Revision 1)
Neat.
 
Xeo
> Their economy sure starts with a BANG! this year, eh?
 
Hm, rich pointers.
 
Oh, cat found the papers.
 
7:53 PM
I don't know what's going on, but this shit is hilarious: twitter.com/#!/search?q=%23tekpubtfstitlesuggestion
 
foo %p = new (std::rich) foo;
Soon there'll be no punctuation to abuse left.
 
Xeo
I don't particularly like the rich pointer proposal
 
What's not likeable?
 
Reflection would be nice.
 
Xeo
@CatPlusPlus Compile time introspection would be nice, but reflection? I don't think so.
 
7:56 PM
@CatPlusPlus I don't think C++ needs full reflection, just get_class_as_tuple. Since the only "useful" thing I can think of is automatic serialization.
 
@Xeo It comes in pay-for-what-you-use mode.
 
Xeo
@MooingDuck Exactly
 
Well, whatever will make it work.
 
Xeo
@RMartinhoFernandes But the price will be heavy for a fully native compiled language like C++
And I really can't think of anything useful you could do with runtime reflection
 
But I suspect manipulating this at compile-time would be painful. If we only had Template Haskell.
 
7:58 PM
@Xeo automatic debugging nonsense, but it's not worth it's trouble
 
Xeo
Reflection itself is painful, imho (if it includes being able to change stuff). Just introspection, that's all I ask for
 
Deriving data file formats, UIs, binary serialisation.
 
@Xeo woot, Doug's module proposal (whatever it is) has an implementation.
 
Xeo
:O
 
I wouldn't mind automatic derivation of embedded language bindings.
 
7:59 PM
@RMartinhoFernandes only kinda addresses the question. For a clean build, it must still parse a cpp file to generate it's interface before it can read that interface for any other file, preventing parallell compilation.
 
For C and Objective C.
 
So it doesn't work with templates.
 

« first day (481 days earlier)      last day (4476 days later) »