« first day (397 days earlier)      last day (4553 days later) » 

12:00 AM
Again "hello" is a contigous memory char (might be char_16 in 11) zero / 0 / null terminated string
I nod you thanks for ideas
I just started with *char_pointer and &char and it seemed very hard
 
"might be char_16 in 11" No, u"hello" would be char16_t const[]
 
yes I noticed c++11 is vague on that.
 
non-prefixed literals are always char const[].
It's quite explicit, nothing vague about it
 
@CaptainGiraffe "" and u8"" string literals are of type char*; L"" literals of type wchar_t*, and so forth, e.g. see here.
 
I went too quickly through the standard it seems, I love this place for knowing better than me!
 
12:03 AM
It's a shame that C++11 doesn't include regular expressions for char16_t and char32_t, though.
 
Hmm, is it possible to use string literals as template arguments?
 
@KerrekSB I read some stuff yesterday to the opposite account, I might be wrong.
 
@CatPlusPlus They can't somehow be converted with user literals?
 
@Pubby Good question, but do you have a for instance?
 
12:08 AM
I want foo<'Hello'> to be the same as foo<'H','e','l'....>
 
template<T> class op () { cout<<T<<endl }}}
no not possible
 
@Pubby No.
 
well unless extreme care, I just figured out a way but its not pretty
 
What is it?
 
See UDLs in the standard, there is no vartemplate form for string literals.
 
12:10 AM
I can code it here but you need to prepare alot
 
actually, I think I figured out a way too
 
Prepared.
 
@KerrekSB Yep, that's the one thing keeping Boost.Regex relevant -- ICU support
@Pubby Technically you can use Boost.MPL's boost::mpl::string<> to achieve that, but then your literals are of the form 'Hell', 'o wo', 'rld' rather than "Hello world", which some people find unacceptable. (Also, the library is technically relying on implementation-defined behavior.)
 
Is the 11 regexp perl compliant?
 
Nothing is Perl compliant.
Not even Perl.
 
12:13 AM
Well Perl is =)
I heard Chomsky went to Japan and sought out a professional swordmaker for a harakiri when he heard about PERL?
 
12:58 AM
@ildjarn Are you saying that Boost actually has an ICU dependence?
Does Boost know about char32_t?
Ah, found it. Very nice!
It uses ICU's UChar32, though, not char32_t.
 
1:15 AM
Is there a "spoiler" markdown?
 
@KerrekSB Not yet; Boost devs are practical, they wait for non-theoretical compiler support first ;-)
@KerrekSB Also, the ICU dependency is optional; without ICU, just plain char and wchar_t are supported (as with Boost.Xpressive).
 
1:37 AM
I kind of got it to work, hehehe: foo<hello_,world_>::print();
 
1:49 AM
although it requires a dictionary file that's over 350000 lines >_<
 
@Pubby Did you check out boost::mpl::string<>?
 
@ildjarn Not really. Aren't they limited to 4 characters?
 
boost::mpl::string<'hell', 'o wo', 'rld'>::c_str() is what it would look like
 
I got it to look like this: foo<hello_,world_,this_,is_,a_,test_,of_,silly_,fake_,string_,literals_,in_,temp‌​lates_>::print();
 
I believe mpl::string<>'s default limitation is 32 characters overall, but is overridable with a macro. Not 100% sure.
 
1:54 AM
32 characters? Or bits?
 
characters
The important part is that mpl::string<> can be passed as a template argument, and consequently can also be the basis for specializations
 
Cool
 
I wrote some answer on SO that did compile-time string-to-integraltype conversion, but aside from that I don't have any actual experience with mpl::string<> so I'm not sure of its overall limitations :-P
 
 
1 hour later…
2:58 AM
@ildjarn Didn't we just go through that the other day with the new user-defined literal thingamajig? You get a template with parameters <char...>.
 
3:29 AM
@KerrekSB Are you talking about that question I asked?
 
A better name than clear?
void clear( wostream& stream )
{
    stream.clear();
    stream.flush();
    assert( !!stream );
}
Re the assert, this is just try-it-out example code. No need to handle the case where USB-drive is removed or similar.
 
If C = 9000;, what is the value of C++ > C?
 
false
 
@muntoo Hah. What's the value of C, I ask.
 
The value of C can be less than C with two pluses.
It's initially 9000.
The compiler that outputs true for that expression is an epic compiler. :)
 
3:39 AM
It outputs false. You're using postfix
 
@Pubby Actually, I think it's undefined. Right?
 
@Muntoo I don't think so. C = C++ is though
 
Oh right. :) Argh. Better keep that expression away from all the C hackers, then.
I've got another one: What's the value of C++ < C, then?
 
Still false
 
Exactly! The statement C++ < C is false! We can trick all the 'C hackers' into using that, then spring the revelation on them!
2
 
3:49 AM
@muntoo What's a muntoo?
 
It is a me.
It is a pseudonym. :)
 
Related to ubuntu?
 
No, it was something my dad used for my LEGO account, which turned into me using it for NXTasy (a forum), which turned into using it for various other things, and eventually StackOverflow. Which kind of sealed it, I guess.
 
Oh wow, I got my pseudonym from a LEGO account too. What a coincidence.
 
I don't think LEGO.com was online ~80 years ago.
(Assuming you got it less than the age of ten, like me.)
And your rep and flag weight is suspiciously close to mine.
 
3:56 AM
The only possible conclusion is that I'm a time traveler
 
And since I am Your Worst Nightmare, you have met your doom, time traveler.
And this doom is going to go eat dinner now.
 
Thank you for your help @KerrekSB
 
@Drahakar No problem!
 
4:19 AM
here is my minimum example for Unicode output in Windows using g++ in a with-sufficient-abstraction-added Visual C++ compatible way, namely, using wide string literal. I suspect they don't teach this kind of thing at univ.
and here is yesterday's corresponding code for Visual C++, for comparision
 
 
1 hour later…
5:40 AM
Hmm. Any way to define structs inside of template arguments?
 
No, but perhaps using std::tuple might help you instead?
foo<std::tuple<bar, baz>>?
 
Don't think that would work.
 
@Pubby you can declare a struct, just not define it. that's useful where you just need some arbitrary unique type.
 
cpx
same rule as you can't define a type in function parameters
 
@AlfPSteinbach That's interesting.
 
6:16 AM
guys
will you recommend Qt over M$ VC++ 2008 ?
when it comes to threading and stuff?
 
lol
 
why do I have to verify that I
am a human being
when I answer a questoin?
0
A: How to create a memory-mapped list of C++ objects

Alf P. SteinbachCheck out Boost memory-mapped files. Cheers & hth.,

and why do have to "retry" to post the link here?
 
guys, any thought abt my Q? :(
 
On Linux Qt is probably better choice. ;-)
 
6:26 AM
im on Win
Are QThreads more user friendly than POSIX pthreads?
 
I have only used boost threads. (And Poco threads a little.)
But they are all just wrappers to the same underlying API.
 
I see
what do you use to make GUI?
 
I have used WinAPI and Qt.
 
MFC sucks right?
:)
 
I don't like MFC. And I especially don't like it because it requires the paid version of Visual Studio.
 
6:33 AM
i didn'
didn't know that
damn. M$
I have a project on VC++. Will it be easier to import this in Qt?
i want to switch to Qt for my future development
 
It will take some time. Depends on how big your project is.
 
but Qt uses VC++ compiler right?
 
Yes. It works with multiple compilers.
I use Qt with VS2008. It's probably the best supported solution atm.
 
so, the files I've included in VC++ as "Linkers" and VC++ directories (Include, Library) will have to be defined in Qt's .pro file?
 
i use qmake and then namke........
 
6:55 AM
ok .thanks. cya
 
7:49 AM
0
A: is there a term for doing this: func1(func2(), func3());

FredOverflowI don't think it's function composition. Function composition means taking two or more functions and turning them into a new function, like f . g . h in Haskell. Note that no function is called at this point. Personally, I would refer to constructs like func1(func2(), func3()) as "nested functio...

 
I'm a bit surprised by people that claim function composition is not a term applied to programming. Obviously never touched a language with first-class functions.
 
8:07 AM
@RMartinhoFernandes Well, there aren't that many mainstream languages where you can just compose two functions as easily as f . g ;)
 
@RMartinhoFernandes there are a lot of programmers who have never touched a language with first-class functions
 
They're all the rage now, with JavaScripts and shit.
 
How do you compose functions in JavaScript?
 
Dunno. You write a compose function?
 
But wouldn't you need a separate compose function for every possible combination of number of parameters?
 
8:10 AM
@FredOverflow It's JavaScript, you can write every function with this signature: function ()
 
Yes, but how would the compose function pass the arguments to the first function?
 
I suppose they do have some kind of composition. I regularly hear claims JavaScript is great because it's inspired from Scheme.
@FredOverflow All JavaScript functions are variadic, and the language provides a means to retrieve all parameters, even if not named in the signature.
 
The Wikipedia example only works for one argument btw:
function o(f, g) {
    return function(x) {
        return f(g(x));
    }
}
 
That works fine, no?
Haskell's . only works for one argument as well.
 
Yes, but Haskell has currying.
 
8:13 AM
You need the boobs operator to compose two-argument function.
 
@FredOverflow If g is a curried two-argument function, f . g needs an f with a function as first argument.
 
You're probably right, I'm still half asleep.
 
I.e. g :: a -> b -> c and f :: (b -> c) -> d.
 
What if I have a function with four arguments? Nested boobs?
 
8:16 AM
I have a factory, ProductFactory, some of the products require config, some of them dont, some of them can have default config, some of them must get the config from outside, how do I define ProductFactory.CreateProduct() ?
 
Hmm. Maybe boobs is extensible. fires ghci.
Hmm, nope, ((.).(.).(.)) doesn't have the right signature.
 
@RMartinhoFernandes but scheme doesn't have that kind of convenient syntax for composition either, afaik
have to spam parentheses, much like you end up doing with a compose function in js
 
Right, there aren't many languages with that neat syntax.
I suppose it's something like (define (compose f g) (lambda (x) (f (g x))))
@FredOverflow No wait, triple boobs does have the right signature after all!
 
anyone ? or shall I ask this question on SO ?
 
Neat. You can just chain more boobs and it works for functions with more parameters.
 
8:25 AM
@Sudhi you'd better ask there, yes. Sounds like the kind of enterprisey stuff the Java crowd loves
 
@jalf : well, not really Java, but a PHP one, however, in my defence, I am only exercising GoF patterns
 
@RMartinhoFernandes What about ((.).(.)).((.).(.))?
 
@FredOverflow That works for four parameters (function composition is associative, so the parentheses are irrelevant).
 
@Sudhi how is that a defense?
"in my defense, I was just firing a gun"
 
Perhaps it was self-defense!
 
8:31 AM
@jalf : I wanted to say, I don't want to worry much about language, but I do care a lot about how much I understand the Factory (and Builder) pattern, and how to use/implement it.
@RMartinhoFernandes : Bingo !
 
despite what some (the Java crowd) likes to believe, the only sane way to deal with design patterns is to use them to describe code, not define it. Write your code based on what makes sense, not whether or not it's a design pattern. And once it's written, you can correlate it with the GoF book and document it by describing which patterns are used in it
7
 
i wish more people realized that
 
What @jalf said.
 
@jalf : that works when you know design patterns, for a beginner like me with < 3 months in OOP world, thats kinda hard
 
@Sudhi then skip the last part. Just write your code based on what makes sense then
 
8:34 AM
people say stuff like "use the visitor pattern" as if that's some kind of concrete answer to a question. it's not, really.
 
@cHao Well, that could actually be a decent answer.
It's a succint way of describing the form of a solution.
Of course, that solution does not need to conform to any "standard" of the visitor pattern.
 
except that the asker then has to know what the visitor pattern is. and if they knew that, they'd already pretty much have the answer on their own, wouldn't they.
 
@RMartinhoFernandes : agreed, and I need to learn different forms of solution in order to gauge which solution will work at current situation
 
@cHao Maybe. Maybe not. Yesterday someone told me to "make a protected constructor". Even though I already knew how to do that, it just didn't occur to me.
 
either way, it doesn't help. patterns don't solve problems; code does. patterns just describe the code
2
 
8:41 AM
Right, and you can either provide a piece of code as a solution, or describe how that code would look like.
"visitor pattern" is a way to summarize that.
 
notwithstanding that just about every pattern described by the GoF has a crappy name that you have to google just to figure out what it is...lol
 
Morning
 
i might remember 5 of them without googling
 
But I agree that things do go bad when people start thinking whether their code "correctly" implements the visitor pattern, or whether they know the visitor pattern "well".
 
@RMartinhoFernandes Are you up for some vtables again?
 
8:46 AM
@cHao I think most of them either have small niches or are just plain bad, so there aren't many you'd really like to remember :)
 
lol...ok. i feel better :)
 
@ManofOneWay Sure, ask away.
 
Let's give you some background info. My assignment is to implement a vtable lookup for private methods in CPython.
The look up should in some way give you an offset in the vtable
 
Oh, so this wasn't just idle curiosity. Cool.
 
Right now, python is using dictionaries in each class
and when you type x.bar() and x is an instance of A it will look for bar in the dictionary of A
if bar is an inherited function, it will look for bar first in A and then in the bases
 
8:49 AM
Yes, that makes sense in Python where things duck type at runtime.
 
By implementing a vtable, we should have a more efficient lookup, this by using some kind of offset. So if class A has function bar() and foo()

class A

def bar()


def foo()


We know somehow know that if we call x.foo() then it's +1 offset in the vtable
What I don't understand is, how should one calculate that offset so that a dictionary lookup is not necessary?
 
GoF doesn't force you to use patterns, but it provides a set of _solution patterns_ which can be helpful. As I am exercising/learning GoF, I do intend to learn/practice them well.
Anyways, I guess this is not the place to discuss usability of GoF, so I will excuse myself. Thank you for your time.
 
The problem is that such lookup requires type information.
 
From what I can tell, you still need to match the actual "bar" with some address
some string compare
 
Right.
The dynamic nature of Python makes it hard to implement a scheme similar to what's common in C++.
In C++ the vtable lookup is fast because the compiler knows about the types.
 
8:54 AM
types in what way you mean?
 
A function signature in C++ looks like void f(A* a);
But in Python it's just def f(a).
(Please correct me if I'm wrong, I don't do much Python.)
 
yes that's correct, I'm not good in Python either
 
If you write a->foo() in C++, the compiler knows he'll find a vtable with the layout suitable for an object of type A.
But if you write a.foo() in Python, it doesn't have any clue as to the layout of the vtable.
I think then you need to either: 1) look up the string "foo" in the vtable, which is now a dictionary; or 2) check the type of a, find the vtable for that type, look up the string "foo" in a dictionary of offsets, and use that offset in the vtable.
Clearly, #2 doesn't gain you much.
I don't think you can get rid of the string lookup (at least not in the general case).
 
In 1) how do you mean look up the string "foo" in the vtable?
 
#1 is exactly what you described earlier. The vtable is the dictionary.
 
9:00 AM
Because the vtable should only contain an array of function pointers as I understand
 
Right, but in this case it would be an hash table mapping strings to function pointers.
 
And in some way we are supposed to add some functionality when the class is created in Python and when we instantiate it, so that we can have a efficient look up when we are calling a method
 
The hash table approach is just a rough baseline though.
I'm certain you can make optimizations.
I'm not familiar with them, though. But I can think of some.
Say many objects are liable of having an __eq__ method (or something like that, whatever implements the == operator in Python), right?
And possibly some others.
 
morning
 
So you could make a vtable that has an array for these common methods, and a dictionary for the rest.
These common methods then turn into a simple offset lookup.
 
9:13 AM
I'm going to include a small, small JIT in WideC
 
I know I'm going to sound like a whiner, but is this answer getting upvotes because people don't even test it, or is it my compiler that's broken?
4
A: templates: how to control number of constructor args using template variable.

ronagI don't have access to a C++11 compiler but maybe something like this could work? #include <array> #include <type_traits> template <int D, typename T> class Vector { static_assert(D > 0, "Dimension must be greater than 0"); std::array<T,D> m; public: templ...

 
I don't see what's wrong with it
what does your compiler give as error?
 
> error: no matching function for call to 'Vector<4, double>::Vector(double, double, double, double)'
And then a bunch of candidates.
The variadic constructor is rejected because of:
> note: candidate expects 1 argument, 4 provided
Which does look weird. But I've learned to not trust GCC errors too much.
 
well, that's quite blatantly not what's written
so in this case, I'm gonna go with "Your compiler error"
 
Damn.
Stupid ideone is taking too much time to serve my requests again.
 
9:20 AM
it hates you and who could blame it? :P
 
Ah, what about what I get on 4.5? ideone.com/BukGh
> error: parameter packs must be at the end of the parameter list
Is this true?
 
yes
else how could you tell the intended formal parameter from a variadic parameter?
 
Ha, then the answer is wrong.
(And my compiler produces crappy error messages. Nothing new.)
 
lol
not sure this is a cause for celebration
that effectively bans SFINAE constructors that have variadic packs
 
I'm not celebrating.
@DeadMG Yeah, because SFINAE is an accident in C++.
vector(blah blha) enable if something would be better.
 
9:25 AM
@DeadMG No it's fine, you can SFINAE with default template parameters.
 
No, GCC 4.5 is wrong. Parameter packs can be not at the end.
> For a function parameter pack that does not occur at the end of the parameter-declaration-list, the type of the parameter pack is a non-deduced context.
But it's a non-deduced context, so still no dice.
 
Yeah, wouldn't be able to call the constructor.
Newer versions should be getting this right IIRC.
 
17 mins ago, by R. Martinho Fernandes
> note: candidate expects 1 argument, 4 provided
So, this is actually correct?
 
Let me play catch up.
 
I.e. it deduces an empty pack, and thus there's only one argument, the defaulted one.
 
9:32 AM
Uh do you have code? I'm lost here.
 
20 mins ago, by R. Martinho Fernandes
4
A: templates: how to control number of constructor args using template variable.

ronagI don't have access to a C++11 compiler but maybe something like this could work? #include <array> #include <type_traits> template <int D, typename T> class Vector { static_assert(D > 0, "Dimension must be greater than 0"); std::array<T,D> m; public: templ...

 
How do you allocate a POD struct on the stack and have it value-initialized?
POD pod = POD(); ?
 
POD pod{};
 
C++03 :)
 
9:35 AM
@RMartinhoFernandes What's the call that gets you that error?
 
@LucDanton Vector<4, double> v(1,2,3,4);
 
Well what can I say; it works fine on my end. GCC 4.5 is just crazy.
Also that answer is suggesting SFINAE when a hard error is perfectly acceptable.
 
I'm running a 9 days old 4.7.
 
What does the constructor look like?
 
Exactly what's on the answer.
(I had to change nullptr to 0 for 4.5 though, but that's not relevant.)
 
9:40 AM
Well yeah, you can't call that. Non-deducible and all.
 
Ok, cool. So I can only assume the OP didn't really want a solution, or has a weird compiler that accepts it.
Also, I don't know why I didn't think of using a default template argument.
 
Do all your SFINAE like that. Since it works for everything, might as well be consistent.
 
Yeah. I think I will.
Do you want to provide an answer with that, or you don't mind that I edit mine?
template <typename... Args,
          typename = enable_if<sizeof...(Tail) == D>>
v(Args... args) : a{ T(args)... } {}
Looks so much better.
 
I don't want to provide an answer, there are already quite a few.
Also what's with using SFINAE when a hard error is acceptable?
 
How would you do that?
 
9:45 AM
static_assert
 
std::forward and rvalue refs, numpty
 
template <typename... Args,
      typename = enable_if<sizeof...(Tail) == D>>
v(Args...&& args) : a{ T(std::forward<Args>(args))... } {}
 
Point being, if you call the constructor with not the right number of elements, an error message on how there's no candidate constructor is needlessly obscure.
 
@DeadMG I don't think that brings much to the table.
I don't expect people to write a vector of objects that should be moved.
 
9:47 AM
none of your business
what if I'm stacking sparse matrices?
 
Well, I'll let the OP decide.
Plus, I have super cool enable_ifs now :P
@DeadMG Btw, what's the JIT for?
 
to enable dynamic languages
and better C interfacing
it only performs two very small but important functions
 
Can't the C interfacing be done ahead of time?
 
not for stateful functions
one: conversion from std::function<ret(T...)> to ret (*)(T...)
 
char_traits<char>::eof() returns EOF and char_traits<wchar_t>::eof() returns WEOF , right?
 
9:57 AM
@DeadMG Oh, neat.
 
and two
 
@MrAnubis I think you made a typo somewhere.
 
calling of functions with statically unknown prototypes
 
Great, I made a typo on the word "typo".
 
like call(void*, pointer_to_argument_memory, pointer_to_result_memory)
 
9:58 AM
That sounds extremely nasty.
 
not precisely
 
@RMartinhoFernandes true , edited
 
the idea is that you would do something like call(GetProcAddress(KernelDLL, "WriteConsole"), stuff, morestuff);
 
@MrAnubis There's no such thing as WEOF. EOF is not a character. It's a special value that is not a character, so there isn't a "wide EOF".
@DeadMG Why not compile time that?
 
@RMartinhoFernandes yes , true
 

« first day (397 days earlier)      last day (4553 days later) »