« first day (309 days earlier)      last day (4654 days later) » 
01:00 - 15:0015:00 - 00:00

3:00 PM
Ah.
 
an expression of array type is nonmodifiable. but that doesn't mean that the array's memory cannot be modified
it just is a compile time concept
 
The original page you linked doesn't say not to modify the array.
Since the input to the algorithm is bounded, its runtime and space are bounded too, so any algorithm that always terminates is O(1) in time and space.
 
yea. The original link is for descriptive purposes only. I am sure this can be done by using some properties of such numbers. If we are allowed to modify the problem becomes too easy. Besides I was specifically told that such constraints exist
wow. I found another similar post. But no solution yet!
0
Q: finding triangulars from array

Nedlininzero-indexed array A consisting of N integers is given. A triplet (P, Q, R) is triangular if and A[P] + A[Q] > A[R], A[Q] + A[R] > A[P], A[R] + A[P] > A[Q]. For example, consider array A such that A[0] = 10 A[1] = 2 A[2] = 5 A[3] = 1 A[4] = 8 A[5] = 20 Triplet (0...

unfortunately no one actually solved it...probably because it was homework.
 
meh i'm rusty
const float *a what does that mean? I can't change the pointer or the contents to which it points?
 
you cannot change the contents
 
cpx
3:11 PM
contents.
 
What does GCC define to signify C++0x support?
 
Or because the O(N log N) and read-only requirements are mutually exclusive.
 
thx
 
@wilx __GXX_EXPERIMENTAL_CXX0X__ far as I know
 
cpx
If you read it from the right, you will get the meaning "A pointer to a const float".
 
3:14 PM
Annoyingly GCC doesn't define __cplusplus to the standard value.
 
if it defines it to the standard value, it is not conforming
if it doesn't, then it is not conforming too.
 
huh?
It's supposed to be 199711L for C++98/03/whatever.
 
Thanks!
 
Having an array with pixels, each pixel representing a certain color, how can I draw it on the screen using open gl?
 
3:30 PM
Is there some C++ container or algorithm I can use to convert an input hexadecimal string say "2F" to its decimal equivalent ? 47 in this case
 
guess glDrawPixels is what I want
 
thanks @Potatos. Does the endianess of the input matter in this case?
 
@user639309 No, text has no endianness. Unless you use an insane format like UTF-16 or UCS-4
 
OK....that's weird. I am solving a problem and it explicitly mentions endianess of the input string
 
3:47 PM
Perhaps the hex is written in half-width Asian numerals and the first 6 characters of bopomofo, encoded in UCS-4, with a layer of base64 for good measure.
 
@Nils You can't change the contents through the pointer, but the contents might still change underneath.
int i = 42;
const int* p = &i;
assert(*p == 42);
++i;
assert(*p == 43);
 
"Find the triangular triplets in this array in O(N log N) time while another thread randomly rearranges the array"
 
@FredOverflow Thx but I was just a bit confused and the faq didn't have the example with const in the first place parashift.com/c++-faq-lite/const-correctness.html#faq-18.5
 
const T* is the same as T const*
 
:)
 
3:52 PM
I used to prefer T const, but too many people seem to be confused by that.
 
Only because not enough people use it yet :)
I like to read int const foo; as "foo is an integer constant." "Foo is a constant integer" doesn't make sense because all integers are constants :vP .
 
iIve put some code in pastebin..how do I share it with you guys? I cannot see a link or anything else..
 
i prefer to confuse people with T const
 
@Potatoswatter Actually, scalar rvalues are never const :)
 
@FredOverflow I just meant in the mathematical sense ;v)
 
3:55 PM
In mathematics, everything is "const", so the concept of const is superfluous in mathematics :)
 
ah...here it is..pastebin.com/60vRAd51
 
Unbound variables aren't const…
 
@Potatoswatter example?
 
@Potatos: This is the problem that mention endianess of the input string: pastebin.com/60vRAd51
 
2*A is not const in math
 
3:58 PM
id : Z => Z | x -> x
i'm practically falling asleep so I've forgotten proper function notation :P
 
@Potatoswatter Not sure what you're getting at, but since there is no such thing as assignment (or control flow) in mathematics, everything is "const".
 
BTW I flagged your message
no.2*A. then I say A=2. I assigned 2 to A
also, the sum construct allows to iterate. pretty much needs to manipulate the "i" iteration var
like E_i=0_to_100(i) == i(i+1)/2
 
@FredOverflow You can define a function, and then evaluate the function at a particular value. Does that involve assigning a value to the function's argument?
 
If I want to visualize heat and have a value from 0 to lets say 1000 or something representing the temp in Kelvin. Then I want to convert it into red, green, blue values for visualization, how can I do this?
 
no. but it involves assigning a value to the function's parameter
etc pp.
 
4:02 PM
@Potatoswatter No, that's just binding a value to a name. You cannot re-bind that name later on to a different value, that's the important point.
 
Or is the function a zen concept unto itself, a graph of edges from one set to another, and you are merely taking a single edge of the graph?
They are two sides of the same coin.
@JohannesSchaublitb Sorry, falling asleep here
 
@FredOverflow The point of an unbound name is that you can bind it to anything in the set of possible values. The only issue is whether in defining the function you have already bound it to everything at once.
 
@Potatoswatter That sounds way too philosophical for me.
 
In computer programming, we typically don't consider that viewpoint. And anyway, then the variable wouldn't be an integral constant, it would be a constant set of integers.
It's a good idea for a new kind of Intercal. A language which attempts to evaluate every function over its entire domain, unless you constantly jump through hoops to stop it.
Such a language would seem to have the property that any program which can crash, will… so it would be related to theorem provers. Gah, I gotta close my eyes guys.
 
4:20 PM
How would a function look to map scalar values to rgb colors? Like this matlab.izmiran.ru/help/techdoc/ref/cmapedib.gif
This is solved, but googling I just can't find anything useful.
 
@Nils What scalar values? Map 0..1 to 0..255 would be x*255, but surely that's not what you meant, right?
 
well it should start with black, then blue, and then red, yellow and finally white
I think it is called multi scale color mapping csc.lsu.edu/~karki/SV/08-ScalarVis.pdf
 
How about a sequence of simple LERPs?
Linear interpolation is a method of curve fitting using linear polynomials. It is heavily employed in mathematics (particularly numerical analysis), and numerous applications including computer graphics. It is a simple form of interpolation. Lerp is an abbreviation for linear interpolation, which can also be used as a verb . Linear interpolation between two known points If the two known points are given by the coordinates \scriptstyle(x_0,y_0) and \scriptstyle(x_1,y_1), the linear interpolant is the straight line between these points. For a value x in the interval \scriptstyle(x_0, x_1...
 
well the input is a scalar from min to max then I need to get three values out of it
maybe having a couple of colors defined and interpolate between them?
 
4:36 PM
@Nils sounds good to me
 
Hi....Can someone explain why my code passed all tests but failed the test for long_str ? It is a really simple program but I am sure I must have missed something obvious. The program is at: pastebin.com/60vRAd51
 
@user639309 Because an unsigned long long can only hold 16 hex digits.
When you parse the string into an unsigned long long, information is lost.
 
@FredOverflow : I am not from a computer science background , so my knowledge is limited. I am just trying real hard to learn. Anyways, what do I do to fix this? what should I parse the string into?
 
I wouldn't parse the string into a number at all. Instead, I would process one character after the other.
 
OK. I'll give this another shot..
 
Als
4:52 PM
This answer and the comment on it gave me a real laugh.
0
A: How do I use a function inside another function in C++?

johnIt's possible, it's easy, everyone does it all the time.

:D
Oops he edited it
 
@user639309 How about this?
@Als Imagine you couldn't use functions... what would be the point in defining them?!?
 
Als
@FredOverflow: Oh hello, Well no point really, but that should have been a comment really.
The OP nicely countered the answer saying "How can I possibly do this easy thing that everyone does all the time?"
 
@Als He's talking about sex, right?
 
Als
@FredOverflow: Ah sex indeed, We are missing the tiger, eh
 
Ah, the real problem was calling a function that wasn't declared yet.
 
Als
5:01 PM
How did you realize that was OP's problem? psychic powers?
This keeps getting better and better, OP's comment:
"Never mind. I fixed my code by moving the function that was being called, above the function that called it. Searching Google said that calling a function inside another function is impossible in C++. By the way, I coded a Battleships game with no functions or classes. Did people close my question as not a real question because they just see 1 sentence describing my question and not bother to read it? "
Yup so no psychic powers for u i see
Oh need to run for now, See you around @FredOverflow, bye for now
 
@FredOverflow : that's a superb solution! thanks a lot!! works like a charm.. How does the case statement change for octal numbers?
i.e what if the input vector specifies the octal representation of the number?
 
@user639309 just remove every case bigger than '7'?
Or leave it as is, the cases simply won't be chosen.
 
makes sense...
 
lol
-4
Q: How do I use a function inside of another function in C++?

desbestI don't think this is possible. If anyone could help me solve this it would be a big help. Update Using Google, the results that came up said that it wasn't possible. I tried the upmost answer and it works. I've fixed my code now by moving the desired function above another one.

 
5:22 PM
@FredOverflow: Kindly look into this code for octal. What changes should I make to prevent x from overflowing? pastebin.com/JCagGWJa
 
@user639309 Same tip. Don't parse the vector into an int, just process each octal digit as it is.
That is, the bitcount of the vector is simply the sum of bitcounts of the individual vector elements.
@JohannesSchaublitb Best question ever, isn't it? :)
 
Just a simple algorithm question:
if a loop runs ' n ' times,but i know that n is fixed everytime then,will the time complexity of that loop will still be O(n) or will it become O(1) ?
?
 
@ArihantNahata Does n depend on the input?
 
5:28 PM
Then it's O(1).
 
k
thanks :)
 
Can we see an example?
> I used scanf() :( I learnt that scanf is outdated and impractical, as if you enter something that's not applicable to the type it wants (enter a letter when asked for an integer), what would happen is an infinite loop. I was going to switch from scanf to fgets but I ran out of time. It's nice that C++ doesn't have such stupid things in it.
LOL, what does that have to do with anything?
> How do I use a call inside of another function in C++?
LOL
 
user457812
Well, pop into your debugger, then grab the nearest phone.
 
@FredOverflow : I was able to solve the octal problem. thanks for the tips!
 
@user639309 You're welcome! If you post the code, I can give feedback.
 
5:42 PM
sure..here it is: pastebin.com/JCagGWJa
@FredOverflow: Any pointers on how I can solve this? I will appreciate a few hints..pastebin.com/YcuTTFdA
btw..this is not homework..i am preparing for an interview
 
@user639309 Oh, I like that {0,1,1,2,1,2,2,3} lookup table!
And that sum+=count[A[i]] is really beautiful.
@user639309 Can you hand the assignments in in any programming language?
 
these are not assignments...I'm preparing for an interview..and i will be taking the test on codility..so I'm searching for "codility interview problems" in Google. In codility you are allowed to solve problems in C/C++/Java/Python
 
@user639309 Up to the % B part, P looks like the classic factorial function.
Since time complexity is bound by B, my best guess is that the maximum output is found for A < B, thus you can just do a brute force search.
 
5:59 PM
OK. I was under the impression that we have to optimize the code by storing the intermediate results of P(N). Just like we do for the factorial problem
 
@user639309 that would be:
int max_power_func_result(int A, int B)
{
    int p = 1;
    int max = 1;
    for (int n = 1; n <= A; ++n)
    {
        p = p * A % B;
        if (p > max) max = p;
    }
    return max;
}
@user639309 You can, and in fact my solution does exactly that.
The next p is computed by multiplying the previous p by A. (modulo B)
This optimization relies on (x * y) mod B being the same as (x mod B) * (y mod B), which I think is true.
 
@FredOverflow Mathematically (i.e. no overflow/rollover) this identity holds.
 
why is the for loop bounded by A?
 
@LucDanton I can always trust my gut feeling when it comes to math!
@user639309 oh crap, it should be B, of course.
You can probably prove that for n > B, no new results will emerge since [bla bla bla] coprime [bla bla bla] QED
 
so if A = 4 and B is 9 , the for loop will execute for 1 to 9, yet in the example the max was found at n = 3..or am i reading this wrong?
 
6:11 PM
At the point where n is 3, you don't know yet that you have found the maximum.
The maximum could be anywhere, so you have to check all values.
 
yes.i get it now..we cannot break early
thanks!
 
We're multiplying by A, not by n. Silly me...
 
any overflow errors or other caveats i should watch out for? they mentioned that A and B can be very large (up to 200,000,000)
i guess p and max can be made long long int?
 
@user639309 Oh yeah, long long should be enough.
@user639309 By the way, in Haskell it's a one-liner:
max_power_func_result a b = maximum $ take b $ iterate (\x -> x * a `mod` b) 1
 
6:27 PM
OK. How about this one? ...the only problem that i have ever solved that involved a chess board was the 8 queens problem and the experience was not particulary pleasant...pastebin.com/nykkFP84
 
@user639309 Have you solved it at compile time? ;-)
13
Q: Solve the eight queens problem at compile-time

Martinho FernandesCan you solve the eight queens puzzle at compile-time? Pick any suitable output format. I'm particularly interested in a C++ template metaprogramming solution, but you can use languages that have similar constructs, like, for example, Haskell's type system. Ideally your metaprogram would outpu...

> using a pair of integers (P, Q) where and .
> Assume that .
There is something missing...
 
user457812
O_o
 
Well, you can always do a brute force. Just try all possible solutions and see what yields the most rice.
Also, don't forget to cook the rice for 20-30 minutes.
 
user457812
Mmmm, rice....
 
i don't know why i began to construct a binary tree with root as A[0][0]. It will have two children nodes A[1][0] and A[0][1] and so on...each node will store its rice value...well I got a nice tree but i'm not sure how to compute max rice value..
 
6:46 PM
max_rice [] = 0
max_rice ([]:_) = 0

max_rice board = max (max_rice $ tail board) (max_rice $ map tail board) + head (head board)

example = [
[2, 2, 3, 0],
[0, 3, 1, 1],
[1, 2, 2, 1],
[4, 1, 2, 2]]

answer = max_rice example
 
what language is that?
 
Haskell
Basically, there are only two fundamentally different languages: C++ and Haskell. All other modern languages are derived from these two ;-)
 
can you kindly translate it to C?
 
So if you know C++ and Haskell, learning every other language should be a matter of 1-2 weeks.
 
or C++
 
6:50 PM
@user639309 Sure, the Glasgow Haskell compiler spits out C at its backend. I highly doubt that would give you human readable code, though...
 
i meant human translate it..
 
Sure I can, but there is no way the C++ code will look more beautiful than its Haskell counterpart...
 
idk..Haskel sounds very academic..
 
It is named after "Haskell Curry".
Have you heard of "currying"?
 
nope...but i just googled it
 
6:52 PM
Basically, every Haskell function takes exactly one argument. You don't need functions with multiple arguments in Haskell, because they can be simulated by currying.
 
never been to a university ..so I've not encountered Haskell yet..can you at least write the pseudocode
?
 
Instead of saying add(a, b) = a + b you say add(a) = \b -> a + b.
@user639309 working on the C++ code now...
#include <vector>
#include <algorithm>

int max_rice(std::vector<std::vector<int>> const& board, unsigned x, unsigned y)
{
if (y == board.size() || x == board[0].size()) return 0;

return std::max(max_rice(board, x + 1, y), max_rice(board, x, y + 1)) + board[y][x];
}

int main()
{
std::vector<std::vector<int>> example = {
{2, 2, 3, 0},
{0, 3, 1, 1},
{1, 2, 2, 1},
{4, 1, 2, 2}};

std::cout << max_rice(example, 0, 0) << std::endl;
}
@user639309 there you go
The second return simply tries out both ways and picks the better one.
And the first makes sure you don't go off the board.
Note that I passed positions instead of slicing the vectors (as I did in Haskell, because it is more idiomatic there).
 
thanks..let me try it at my end..
should it be + board[x][y]?
the second return..
 
No, the y dimension always comes first in my programs.
First the row, then the column.
But it would not matter a bit if you changed it (as long as you also changed x and y in the line above it).
By the way, where did you find these problems? I find them quite interesting.
 
This problem is given under the category of dynamic programming..so i think there must be some scope of optimization
 
7:05 PM
I'm not familiar with dynamic programming. All I know is you usually keep a table of old results to be reused later or something.
 
These are problems from a Codility test that I took.
 
Is "codility" a term I should be familiar with?
 
seems useful
Does it cost money?
 
they mostly pic questions from coding competitions like TopCoder or ACM
not for the test taker
i don't think its 100% fair.....idk...for example your brute force approach will get less points...maybe 60 out of 100. ..does that mean u should not be hired?
i think that would be a loss to the employer..if they dismiss a candidate as good as you because of a codility test
 
7:13 PM
@user639309 Why, because the brute force approach takes too much time?
 
yes...codility tests the run time efficiency of your program..and gives points accordingly
 
Honestly, if someone else writes a "dynamic programming" solution to the rice problem, that someone is a better programmer than me.
 
no..he is better at writing this particular program than you..
can we save the computations : max_rice(board, x + 1, y) and max_rice(board,x,y+1) in a map or something....i wonder what the key to this map would be..
 
Of course, the function will be called many times with the same values of x and y, and the answer will never change.
 
7:34 PM
yes..but how do I map a given x,y to the result of max_rice
 
@user639309 Standard caching technique?
if cache already contains entry for x,y
    return that entry
else
    compute the result once
    put it into the cache
    return the result
 
true...the difficulty is in the actual cache.if I use std::map<key,value> for my cache, i know the value to be stored is the result of max_rice..but what is the key? How do i do a lookup?
 
The key is (x, y)
 
0
Q: C++0x T operator+(const T&, T&&) pattern, still needs move?

towiSome time ago I was told, that the usual pattern to implement two-ary operators needs a final move in the return. Matrix operator+(const Matrix &a, Matrix &&b) { b += a; return std::move(b); } But now there is the special rule that in a return the compiler may treat the ret...

huh? I don't see the need for std::move, but perhaps I haven't understood it
 
i still don't get it..i must be thick...how do i convert (0,1) to a key?
 
7:45 PM
@user639309 How about std::make_pair(0, 1)?
 
@Tony The rule is for local variables
 
@LucDanton nope, also for parameters
 
what is a good and pretty tool for groups that has wikis
 
@TonyTheTiger is that signature for real
 
sure, why not? :)
 
7:47 PM
@FredOverflow Well I'm not sure you're contradicting me.
 
it's ass-ymetrical, and i think maybe && can't bind to lvalue?
 
@LucDanton If parameters are local variables, then there is no contradiction.
@AlfPSteinbach It cant. He probably has at least two additional overloads.
 
@TonyTheTiger For instance std::unique_ptr<int> foo() { std::unique_ptr<int> p; return p; } will compile even without a return std::move(p);
 
can't we do + reasonable without overload
 
@FredOverflow It's more of a 'I have one hand' vs 'I have one and only one hand' situation to me.
 
7:48 PM
@LucDanton At least on current g++ :-) VS2010 is not conformant in this respect, sadly.
(or was it the other way around?)
 
I don't use MSVC but I know some versions of GCC can deal with my example.
 
@user639309 Or you can just use another 2D vector for the cache, since it is dense anyway.
@user639309 Anyway, here is my solution with a map for a cache.
 
I wonder how much it makes sense to worry about T foo(T const& t) { return T(t); } vs T foo(T t) { return t; }
First one is one copy + at least one move/elision, the other is one copy/move + at least one move/no elision. (Not sure about all of that, I seldom worry about those things).
 
If moving a T is significantly faster than copying a T, I'd go for the foo(T) approach. Otherwise, I definitely wouldn't.
 
I should be making the comparison on foo(T&&) + foo(T const&) overloads vs foo(T) though.
(i.e. perfect forwarding is not at hand here)
@FredOverflow Haha did your last comment throw a wench into the reasoning.
References aren't objects. But on the other hand, the paragraph that mentions 'the name of a non-volatile automatic object' doesn't apply as we have a function parameter.
> When the criteria for elision of a copy operation are met or would be met save for the fact that the source object is a function parameter, and the object to be copied is designated by an lvalue [...]
Well arguably then the object referred to by the function parameter (the reference) is not a function parameter itself (most of the time...).
I'm so not answering that question!
 
8:10 PM
LOL
 
@FredOverflow Say, did your previous question about value parameters explicitly mention non-references parameters? If so, a comment would do good to point out that the new question is not an exact duplicate.
 
What, Java can't optimize tail recursions into loops? :(
 
 
2 hours later…
9:57 PM
@hexa :) Yeah, you think I can understand you, Brazilians?
 
10:24 PM
template <typename T>
struct blah {
public:
    static_assert(std::is_integral<T>::value, "T must be an integral type");
    blah() : value() {}
    blah(T t) : value(t) {}
    operator T() const { return value; }
    T raw() const { return value; }

private:
    T value;
};
static_assert(std::is_pod<blah<int>>::value, "blah<int> should be a POD");
Isn't this a POD?
That last static assertion fails on GCC 4.5. Should I assume is_pod is not yet working on GCC?
 
Not a pod because there is more than one access specifier.
IIRC of course. Since POD is more of a C++03 thing the rule here is that there is an access specifier at all.
Also not a POD because there are user-defined constructors...
 
Ah, got it, it's the default constructor.
 
That's pretty much the worst POD-wannabe you could find, no offense :)
 
@LucDanton Yes, you can have a user-defined ctor.
You just need to have a default ctor defaulted on the first declaration.
The "same access specifier" rule only applies to data members.
If I do blah() = default; it's fine.
 
@RMartinhoFernandes Am I misremembering that for C++03 having an access specifier at all is problematic?
The new, relaxed POD rules are standard layout + some trivial construction correct?
 
10:33 PM
Maybe. I wasn't into C++ when there was no C++11 :)
 
I assume that 'same access specifier' rule is from standard layout.
 
@LucDanton Yes.
@LucDanton And yes.
 
And I gather from the defaulted at first use that trivially default constructible is required, too.
 
Yes.
POD = standard layout ∩ trivial.
 
@RMartinhoFernandes I see. I remember papers discussing how to 'fix' things like class maybe_pod { public: private: int blah; }; and the like.
 
10:35 PM
Ok, so now this works: ideone.com/ORWhE.
A crazy idea I had.
 
I didn't realize a standard layout could have all private data members and still have public member functions. That's neat.
I find it confusing that T(swapped) != swapped.raw().
 
The point is to have T(swapped42) == 42.
 
I'd prefer an informative name. Perhaps .original()?
 
Ah.
But it's not the original value.
 
Honestly since I'd use the type to do an endianness conversion having T(swap_endian<T>(t)) be a round-trip confused me.
 
10:42 PM
The idea is to be able to store it with the endianness you desire and use it transparently.
It was motivated by the need to continuously do endianness conversion when writing network packets.
 
Alright. Then the name of the class confused me.
i.e. I first thought to use it for a conversion.
 
That's why I worked with the POD restriction.
 
But the interface doesn't reflect that use.
So the use is
client stores its T's into swap_endian
 
Yes, and then I can just directly bitblast that into places that expect data of the opposite endianness, or just alias the value directly with a char*.
 
Whoah, bad Wifi spots, too many timeouts :(
Anyway, your main does a good job of showcasing the use cases.
Say, I think you were interested in my codebase once or twice.
 
10:53 PM
Yes. You seem to come up with cool ideas :)
 
Well, I've been shopping around for build systems.
And since I found nothing to my liking I gave up.
So here's my code without a way to build it.
 
Did you try SCons? The @Cat seems very fond of it.
 
I looked a bit at it today but I'd have needed a clear head to really try it, so I actually have yet to give this one a real try.
Too much 'try' in previous sentence. Head hurts.
 
> Bitbucket will be unavailable for a few moments 7:00pm, 21 August 2011 (UTC+01:00) for maintenance and upgrades.
Er, did someone mess with my clock again, or is this in the past already?
 
Possibly DST/summer time confusion.
 
10:57 PM
I'm on UTC+1 and my clock show about midnight.
 
Nah, someone didn't bother to remove that banner I guess.
Time to take the site into maintenance to remove that!
 
Anyway, not everything in my repo is actively used. Some of the stuff is something I thought was a good idea at the time and I haven't refined them due to not having a use. channel comes to mind.
It's my personal "maybe I will want to have that as a library" library.
I find it hilarious that big parts of it have sprouted up to support what I thought was a good idea.
e.g. named_parameter is here so that make_unique (from unique.hpp) can be used in almost any situation.
 
I was looking at that just now.
 
Similarly all the forward_* stuff is here for the thread_pool.
 
11:08 PM
My make_unique is just the simple forwarding function.
 
Aye, mine can do that as well.
 
And much more I see.
 
Unfortunately the latest GCC snapshot has broken the unit tests for named_parameter. Just the unit tests though, make_unique still works fine.
 
You know that technique of SFINAEing with a defaulted template parameter we confirmed the other day?
I wonder why I haven't seen it before.
 
Well, not two days after I started using it I stumbled upon a discussion on the boost lists.
That was then that I discovered that it's not only more convenient than the other techniques but it works for e.g. conversion operators.
Whereas you can't do template<typename U> operator typename std::enable_if<foo, U>::type() what with no deduction.
Speaking of PODs, I have to test the POD-ness of overload
 
11:15 PM
Now it's easy :)
<type_traits> is awesome.
2
 
Ah crap. On the one hand I would have liked it'd be a POD for POD parameters, on the other hand I explicitly disabled default constructions for pointers.
Oh well.
 
In one of the STL (the person, not the library) videos about the "STL" (the library, not the person), I remember he mentions that std::copy has some smarts to use memcpy or memmove when possible. How was that done before without things like std::is_pod?
(I'm assuming std::is_pod cannot be implemented without magic, maybe I'm wrong.)
 
Compiler magic.
But the kind of compiler magic that a compiler writer really wants to put in the feature list.
 
It's nice to have that power at our disposal now :)
 
It really is.
 
11:22 PM
Pro tip: when you're pouring water from a large bottle into a smaller bottle, don't try to close the larger one with the cap from the smaller one. It will end badly.
 
Yes, I always stop pouring when I do that.
Mmmh.
I'm extending support of overload to member functions.
I'm at the point where I'm generalizing to every possible cv-qualifier combination.
Now, so as to not be too restrictive, I'm made the signature of operator() as: template<typename C, ...> Ret operator()(C&&, Args... a) const;
There's a bit of SFINAE because there are two such operator().
One for pointer and pointer-like arguments, one for object-like arguments.
Much like std::bind is compatible with objects pointers, in fact.
Now the problem is
Instantiating an overload<void (T::*)(), void (T::*)() const> will fail.
 
Because o(some_object) would be ambiguous, the two using declarations in the innards of overload are conflicting.
Should I change the signature of operator(), and then to what?
operator()(Class cv& + operator()(Class cv &&) + operator()(Class cv*)?
That drops support for smart pointers.
I suppose I could actually SFINAE that last overload to anykind of parameter that won't convert to Class cv& or Class cv&&.
Well, let's try that.
Not so elegant when I have to support lvalue/rvalue *this though, as I'm using the preprocessor.
Class & const & won't compile heh.
 
11:40 PM
Of course.
 
template<typename Class, typename Ret, typename... Args> class overload_element<Ret (Class::*)(Args...) const&>: private overload_element<Ret (Class::*)(Args...) const> { using base::base; using base::operator(); };
(assuming base to alias the, well, base)
This one enables a (probably) useless operator(Class const&&) though.
 
GCC already to supports lvalue/rvalue this?
 
Nope.
Neither does it support inherited constructors.
 
> No doubt you also write lock-free multi-threaded code sharing state in a way which is as efficient as possible but still rock solid. What the heck are you doing reading this in the first place?
lol
 
I can already guess where this is from.
 
11:47 PM
It's not an SO comment. Was that your guess?
 
I guessed wrong!
 
I still get a conflicting using declaration :( I guess I can scrap support for smart pointers.
@RMartinhoFernandes Whoah, that's a long article.
> Leap seconds baffle me.
 
Well, it's hard to explain why those APIs suck.
Unlike say, the Java APIs, they suck in subtle ways that Average Joe won't even think about.
 
Thank god for <chrono>!... Not that I'd use that for dates.
 
11:55 PM
I haven't looked into <chrono> yet, but I'm not sure it covers all the ground NodaTime strives to cover.
I'll put that on my TODO list.
 
Well, I cheated: it only covers the time part.
So an epoch + a number of seconds using (compile-time) rational arithmetic.
So no need to deal with leap seconds, timezones, calendars, etc for converting to a date
Boost.DateTime covers that IIRC.
 
Yeah, that's just the core of it. Basically what NodaTime's Instant type does.
@LucDanton I'll look into that, might be good to have two already existing APIs to serve as guides.
(So far we've been basing on Stephen Colebourne's JodaTime.)
 
01:00 - 15:0015:00 - 00:00

« first day (309 days earlier)      last day (4654 days later) »