« first day (319 days earlier)      last day (4630 days later) » 

8:00 PM
As... an argument?
 
remove_if(begin, end, pred); where Pred pred; has been declared before.
Or similarly remove_if(begin, end, Pred());
 
Let's say the function is named CloseTo() and takes a Vertex(6,7):
remove_if( shapevec.begin(), shapevec.end(), CloseTo(Vertex(6,7))
Now my custom object that contains a vertex is named ShapePtr.
Should the CloseTo function have arguments like CloseTo(const ShapePtr &s, const Vertex&v) ?
 
no
 
Are you trying to call CloseTo member on those objects, or what?
 
@ManofOneWay no, you'll have an operator()(const YourCustomType& obj)
 
8:02 PM
it needs to take a const Vertex& v, and return an object which can be called with a const ShapePtr& s
or have it as a type and make the original call the constructor
 
You're probably looking for std::remove_if(xs.begin(), xs.end(), [](X& x) { return x.CloseTo(Vertex(6, 7)); }); or something like that.
 
@ManofOneWay If you want to remove vertices that are close to another vertex I suggest you use a function object with state, not a freestanding function.
 
yes, a lambda would easily be the easiest solution
but I wouldn't assume C++0x support
 
Try to tell the larger picture of what you're trying to achieve rather than describe the details.
 
You want to implement close_to as a function object. Your ctor will take one vertex, and just store it. Then your operator() will take one vertex as its argument, and test whether the passed-in vertex is close enough to the stored vertex.
I'm not clear enough about how you're using ShapePtr to comment intelligently on how it figures into things.
 
8:09 PM
no, he wants to take one ShapePtr
I would imagine it's something like typedef shared_ptr<Shape> ShapePtr;
 
Does a ShapePtr have one or more vertices, and you're trying to see whether any of those vertices is close enough to a specified point?
 
@LucDanton It's a school assignment, where I need to remove custom Shapes (Rectangle, Circle and so on) in a list that are close to a point (how close, I can choose). The list contains ShapePtr elements. (Elements that points to Shapes).
 
I wouldn't worry too much about it- the only important thing is that his test has the signature bool CloseTo(const ShapePtr&, const Vertex&)
 
@ManofOneWay What is used to compute the distance? A freestanding function? A member function?
 
@DeadMG No -- he almost certainly wants to pass the initial point he's testing against in the ctor, and then operator() takes one argument of some type that tests one or more other vertices against the one that was passed in the ctor.
 
8:13 PM
So first we have to read all the shapes from a file

ifstream is("fil.dat");
istream_iterator<ShapePtr> shapein(is), endofshapein;
list<ShapePtr> shapelist(shapein, endofshapein);

this has already been taken care of, now the next step is to remove certain shapes that are close to a point

shapevec.erase(remove_if( shapevec.begin(), shapevec.end(), CloseTo(Vertex(6,7))), shapevec.end());
The CloseTo function is not declared anywhere, that is our job
 
Oh okay.
 
but I don't know how to, as I said before I thought I could do something like:
bool CloseTo(const ShapePtr &s, const Vertex &v);
 
@JerryCoffin Pretty sure that he specified exactly what he wants
 
@JerryCoffin agreed ;)
 
I assume you want hints, not a full answer.
 
8:15 PM
@ManofOneWay You want to make it a type that stores the vertex and has an operator()
 
@ManofOneWay If the function is declared that way, then CloseTo(Vertex(6, 7)) is an error because you only pass one argument to it.
 
class close_to {
vertex origin;
public:
close_to(vertex init) : origin(init) {}

bool operator()(vertex const &v) {
return distance(v, origin) < limit);
}
};
 
I thought it automatically passed an element from the list as well
 
class CloseTo {
    Vertex v;
public:
    CloseTo(const Vertex& vert)
        : v(vert) {}
    bool operator()(const ShapePtr& s) {
        // return test
    }
};
@ManofOneWay It automatically passes an element from the list- but that's not "as well", it's "only"
any other arguments you have to take care of yourself
 
@ManofOneWay try something like struct is_close_to{ const Vertex& p; is_close_to(const Vertex& point) : p(point) {} bool operator()(const Vertex& point) { /* return true if point is near p, false otherwise */ }};
 
8:17 PM
guys
read his damn code
the test takes a ShapePtr
 
With a ShapePtr, he'll apparently want something like walking through the list of vertices in the shape, and figure out whether any of them is "close enough" (and possibly whether the point is inside that shape, so if the limit is (say) 10, and you have a point exactly in the middle of a 50x50 box, it still shows up as being in there....
 
Hello Folks! I am having a bit of a tough time understanding a minor detail in Duff's Device and I was wondering if the guru's here could lend a hand. The wikipedia article and the answers here(goo.gl/Thnbc) all involve an initial loop counter which is computed as int n = (count + 7)/8; and I was wondering what is the reason behind the + 7.
 
just because you think it ought to take a Vertex instead, well, it doesn't
 
@ManofOneWay But what does it pass it to? In other words, what's the type of the would-be expression CloseTo(Vertex(6, 7))? Argument passing doesn't work by textual substitution.
 
@DeadMG Yes, but he hasn't told us enough about a ShapePtr to write code showing how to work with that. I just suggested a general idea, but without knowing more about it, it's impossible to be more precise than that.
 
8:19 PM
who cares? it's his job to implement the actual boolean test anyway
 
he already got the solution then ;)
 
Thank you guys
 
@DeadMG how's it going? Long time I don't join here.
 
same old same old
I feel sick, I hate my course, I need to write more code and play less games
 
@DeadMG Yes, but the point is that it's a two step process: you pass the "center" to test against in the ctor, and the individual items to test against that will be passed to operator() automatically. Originally you said: "the only important thing is that his test has the signature bool CloseTo(const ShapePtr&, const Vertex&)". Your more recent comment showing the class CloseTo got it right...
 
8:22 PM
@DeadMG we're on the same boat, except that I'm not doing any course right now.
 
@JerryCoffin I said that it was the signature of his test, not the signature of any individual part in it
 
@DeadMG what about that rendering thing (engine?) you were writing?
 
I paused that a long time ago
mostly because C++ sucks and I wanted to write my own language
since then I've discovered that compiler-compilers suck and I need to write my own- of course :P and also doing work on said language
 
@DeadMG but it's not the signature of anything.
 
@DeadMG haha, C++ also frustrates me sometimes. Mainly when I need to write copy ctors etc.
 
8:24 PM
@JerryCoffin It is the signature of the test. The fact that it has been effectively curried into two different stages is irrelevant.
@jweyrich That I don't mind so much. It's more like the horrendous preprocessor, the infinite cocking around when dealing with templates, the poor type deduction
 
@DeadMG poor type deduction in which sense? I always thought the type deduction did a terrific job (except for the NULL ambiguity for some pointer type and an int).
 
for example, no decltype on member variables during member function deduces
and that bullcrap around when you're using CRTP and can't get type data from the derived class
and how about no deduction of return types?
 
oh, ok, you're talking about c++0x - haven't used many of the new features yet - I'm not on a C++ job right now :(
 
oh, yeah
C++03's type deduction support is virtually zero
C++0x's is a little better but crumbles hard whenever you try to do something more complex than decltype(a + b) in it
 
@DeadMG right, I though you were talking about deduction for overloading, SFINAE, etc.
 
8:32 PM
It's all self inflicted really. The SC can't mandate big changes because implementations have a hard enough time following the specs already; so they do incremental changes. But the incremental changes build up until we have a kitchen sink language. That is hard to implement closely to the specs.
 
@LucDanton I agree- I think that the committee made some bad design decisions too early
 
@LucDanton I hate that they keep backwards compatibility with all the legacy bad decisions :)
 
I always wondered why language versioning wasn't more common. But apparently it's not that great either.
 
evening
 
Blah.
I mean, good evening.
 
8:43 PM
what's new
1
Q: Ruby C Extension - 64bit pointer being truncated causing a segfault

user781331I'm working on trying to get a ruby extension written in c, working with ruby 1.9.2 on Mac OSX. I keep getting a segfault caused by a 64-bit pointer returned from a function being truncated to a 32-bit value and trying to access low memory. Here's what I've figured out about it. VALUE is a long,...

I have a feeling he's returning a pointer that's within function scope from the function
but I don't know this framework and I don't what the type of VALUE is
 
It's a long. Says so in the question.
 
oh
then I don't get how it can be truncated
 
It's a long in a program that won't compile unless it's an 8-byte long. Clearly using int64_t wasn't worth it.
 
But is it really 8-byte long?
> (...) returned: 0x009d52a0 instead of 0x1009d52a0
 
well, I guess that's implementation defined right?
 
8:49 PM
Note the mismatch in the number of digits.
@TonyTheTiger Yes.
 
the x64 architecture is currently 48-bit wide
 
@RMartinhoFernandes Not my problem.
 
instead of 64bit
 
so using a long would be the wrong thing
 
^ Japan ...
 
8:50 PM
lol, is that your book?
 
Nope, just found this on reddit :)
 
From the comments: "This is a page from a book intended for young adults to learn english. "
 
holy fuck
 
@TonyTheTiger No, that's not in the book.
 
8:52 PM
Yeah, it's from the comments.
 
^ Same character as from the book.
 
@RMartinhoFernandes yea sorry, I was thinking about sex
lol
 
Excuse me guys, if I want to use the sort function, to sort the elements in the list
what's the best practice?
 
Er... use it?
 
std::sort
or container.sort()
 
8:57 PM
Yeah for std::list it's fine to use the member.
std::sort is for iterators.
 
Time to goto home. Gone.
 
@DeadMG Could I create a function object here also?
 
@ManofOneWay if you want a custom comparator for your sort function, then yea create a functor
 
I have a list of shapes and want to sort them both by x, y and area values
so I need three sorting functions
 
You can do with just one.
 
9:03 PM
lulz
euh wtf?
 
lol
 
Because screenshots are for pussies.
 
His hard drive is gone.
 
Where will he save the screenshot?
;)
 
9:11 PM
:P
 
So I'm (re)writing a CSP-style channel. I'm thinking of splitting it in two classes, one for each 'end' of the channel. Any idea for good names?
 
what on earth is CSP?
 
Why, that book from Sir Tony Hoare.
Not just a book but also a formal language.
 
so it's message passing
 
That's really besides the point you know.
 
9:16 PM
it's totally the point
 
Well okay I'm all ears then.
 
well, you can find concurrent queues in which to place messages and actor-based models in TBB and PPL
 
Okay, let me make myself more clear.
I used to have a channel<T>
I'm splitting it into two classes; one for each end of the channel.
I'm trying to think of meaningful names for each class.
 
the PPL has ISource<T> and ITarget<T>
 
read_channel, write_channel?
in/out?
 
9:18 PM
in/out somewhat mirrors iostreams
 
failing anything else, just name them as they are- channel_begin, channel_end
 
ichannel looks so wrong though so I'm going with in_channel
@DeadMG Arguably they're both ends!
 
then why have two separate classes?
 
Yeah, there's no "beginning", only ends.
@DeadMG To make clear who reads and writes with the type system.
 
if the messages only pass one way, then that way has a beginning and an end
 
9:20 PM
If I see void(out_channel put_back) it's clear from the type that this function/functor/whatever is a producer.
 
@DeadMG Ok, that's a way to see it.
 
Also I had ownership issues before.
 
hello world\n
 
i.e. a producer had to be void(channel<T>& put_back) and the channel had to outlive the producer.
I'm going with shared ownership with this one.
Hopefully my intent is clear and what I'm doing is somewhat sane?
 
As in out_channel and in_channel are views of the underlying "real channel", and that "real channel" is shared by all the views?
Or maybe I misunderstood.
Or maybe you're not clear.
 
9:24 PM
Yes.
template<typename T, typename Allocator = std::allocator<T>>
std::pair<in_channel<T, Allocator>, out_channel<T, Allocator>>
make_channel();
Each channel type is movable but not copyable.
 
<3 move semantics
 
Whereas having a two-ended, one way channel<T> is simply unworkable.
i.e. can't move it to the producer so the code that async's the producer must own the channel??
 
Btw, in/out is also the terminology used in Go, which borrows from CSP.
@SalvatorePreviti Hello.
 
9:36 PM
kinda my feelings on Help Desks in general
 
Do you use the Shiboleet trick?
 
So, I have detail::channel_shared_state which I assume is self-explanatory and is a friend of in_channel, out_channel and make_channel.
Inside make_channel, I use std::make_shared<detail::channel_shared_state<T, Allocator>>()
Isn't there some access right issue here?
 
They're friends, what would the issue be?
 
9:41 PM
Shouldn't it be a friend of make_shared?
 
Oh yeah, the generated constructor is public
@CatPlusPlus Is this a reliable thing to do though?
 
no
especially I noticed this problem in Visual Studio- they do the actual construction in a factory function in the implementation
 
i.e. as usual the signatures of functions of the Standard Library are not guaranteed, are they?
 
no, that's not the problem
the problem is that the friendship cannot be transferred
 
At least it's a separate one.
 
9:43 PM
so if they delegate to any helper functions, they aren't friended
and won't get access to your stuff, even if you friend the original function
 
Well I'd rather have a type in a detail namespace with public constructors and all private members rather than forgo make_shared.
 
Nasty.
To me, namespace detail pretty much means private.
If you mess with it, you deal with it.
 
Still, Boost.Serialization uses some magic to circumvent that.
 
"Private unless I'm feeling like poking around."
 
IIRC make boost::serialization::access a friend and everything goes right (don't ask me why/how).
 
9:46 PM
they probably just do all the work in the function itself
 
What function?
 
b::s::access is a type?
 
I suspect.
With a lot of static helpers to 'decapsulate' the friending types.
And/or some kind of inheritance abuse.
 
Probably they do all the friendship work in that type, and other types delegate to it.
 
Seems like a cruel thing to require implementations to have if we'd ask for a std::access.
 
9:50 PM
hi is this good code practice, "bool aw = x == y;"?
 
tes
yes
 
I don't see anything wrong there.
 
good, i thought so
 
Maybe aw could have a better name.
 
I think they should just add an implicit "caller" along with the implicit "this"
 
9:51 PM
true, first time I've seen == outside of a control statement
 
void f() { caller(); } <- adaptable mutually recursive function!
 
bool aww = Puppy.Cuteness() == Cuteness.Adorable;
 
puppy!
 
lol
 
I'm done, anyone willing to laugh at comment on my CV?
 
9:53 PM
are there any other cases where != and == can appear outside of a control statement?
 
of course
they're just operators like any other and can appear wherever expressions are expected
 
They can show up in comments too!
 
bool aww = Puppy.Cutness() != Cuteness.Horrid;
 
@RMartinhoFernandes: Is that your real mobile number?
 
Think so?
I wish.
 
9:54 PM
Lol.
 
another thing is
 
You've misspelt 'Some city'.
 
the language doesn't seem to be consistent
 
writing "x == y;" isn't very useful though?
 
a lot of the field names and stuff are in English
 
9:54 PM
@CatPlusPlus No, I didn't. That's where I live: Some citiy..
 
You can write entire program in operator==. It's stupid, but you can.
 
then some of it is in, I presume Portuguese?
@Ricky65 No more or less so than x + y;
 
Yes, Portuguese. It's the name of my university and my degree.
 
true
 
9:55 PM
I didn't bother translating.
 
@Ricky65 can be useful, especially in algorithms that use table lookups.
 
and the language names
 
but "x == y;" has no effect?
 
@DeadMG Oh, weird.
How did that happen?
 
9:56 PM
return x==y?
 
@Ricky65 Same as x + y;- you can write dozens of nothing expressions in C++
 
@Ricky65 Depends on the types and whether it was overloaded.
 
also, in English, I believe it's usually referred to as "Software Engineer" and "Software Engineering", not "Computer Programmer"
 
true but "x == y;" on its own is useless, w/o overloading
 
Um.... well with operator overrides, you can't be certain that x == y does nothing. Maybe you have an equivalency check count on the class?
 
9:57 PM
although if you're only shopping around in Portuguese then that's not helpful
 
I'm not sure I have the financial means to move out yet.
 
another thing is
 
Software engineering is a bit more than programming, AFAIK.
 
you've listed OOP as a skill
 
And I really dislike the term Engineer when applied to software..
 
9:57 PM
what, your functional programming isn't up to scratch?
 
Hmm, that. I could add it. It can't hurt, can it?
 
class apple { operator == (orange) { throw new ComparsionInvalidException("Ok, that's so lame...");} };
 
ok
as long as you can actually program functionally :P
 

« first day (319 days earlier)      last day (4630 days later) »