top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What issue do auto_ptr objects address?

+2 votes
68 views
What issue do auto_ptr objects address?
posted Dec 29, 2014 by Emran

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
+2 votes

"Imagine you have a singly-linked list L1 (of integers, for simplicity) with values 0 to 9. There is another singly-linked list L2 (again, of integers) with values 0 to 5.

As expected, the next-pointers of the last nodes of both the lists point to NULL. Now, I modify the next-pointer of the last node of L2 to point to the 7th node of L1 (which has the integer 6 in it). We now have a 'Y' : two lists which merge into one. How would you find the node where the two lists merge?"

The problem is not difficult. However, my colleague came up with the question "How would one _create_ such a 'Y' from two std::list or two std::forward_list objects in C++?". The constraint is that one _must_ use the STL list/forward_list and other STL functions only. He can't figure it out and neither can I :-(

I agree that creating such a 'Y' would be inviting trouble but still, how would one do it if one wanted to? I tried to google for "combining/merging/joining multiple lists" but the usual answers (splice, std::move, etc) don't seem to help.

0 votes

I am experimenting a bit with exactly how much is (user-wise, anyways)
conveniently implementable with C+11 variadic templates and a strict
construction/destruction pattern. In addition I use this project for a
playground for other techniques, such as designing everything through
composition and mixins, as well as the occasional functor, for maximum
flexibility. Repository: https://github.com/lycantrophe/Curses-- [1]

So far so good, but all currently implemented widgets have been very
basic and only wrapped around the Widget class. What I am having trouble
with is the "ButtonGroup" widget.

This widget is, as the name suggests, a group wrapper for the Button
class that handles things such as a common return value, behaving like
an external entity towards user code and, most importantly, being
responsible for handling input and focus switch between the buttons in
the group it governs.

What I am trying to accomplish is being able to forward a set of
arguments to the individual, underlying buttons. These parameters
include text value (the string to be displayed), individual return
values and individual anchors. Things like border style and behaviour in
regard to focus toggle will of course be shared between all buttons.
Some code to clarify:

 template< typename Return >
 class ButtonGroup {
 ButtonGroup();
 ButtonGroup( const Anchor

 template< typename Action, typename... Args >
 ButtonGroup(
 const std::initializer_list< std::string >& texts,
 const std::initializer_list< Action >& actions,
 const std::initializer_list< Anchor >& anchors,
 const Args

 Return trigger();
 void redraw();

 private:
 std::vector< Button< Return > > buttons;
 typename std::vector< Button< Return > >::iterator current;

 };

Return is the return value from the buttons (typically true/false, but
can be anything). Action is a template as it requires a functor, whereas
bool is treated as a special case (simply creates a functor for you).

This did not work; both gcc and clang/llvm were unable to properly
deduce my use of initializer lists (from the ButtonGroup( const Anchor
to provide me with a vector, array or whatever suitable structure
that holds:
[ Button( "OK", true, Anchor( 0, 0 ), Button( "Cancel", false, Anchor(
0, 3 ) ) ], from here on [ Button, Button... ].

Sending the arguments in a structured matter, such as grouping all
strings, all return-values and all anchors would be fine as well. Now,
it is NOT acceptable to take the actual Buttons (or pointers, for that
matter) as arguments during construction as this would require double
construction and, as you probably see from the other construction code,
defeats the purpose of this style.

Are there any ways I can try to accomplish this? Any other criticism
will be welcome as well.

0 votes

how to manage the secured connection error in HTTPS?

...