copying elements from a <list> to <deque>

Discussion in 'C++' started by arnuld, Sep 25, 2007.

  1. arnuld

    arnuld Guest

    It works fine. any advice on making it better or if I can
    improve my C++ coding skills:

    /* C++ Primer - 4/e
    *
    * Chapter 9 - Sequential Containers
    * exercise 9.18 - STATEMENT
    * Write a program to copy elements from a list of "ints"
    * to 2 "deques". The list elements that are even should go into one deque
    * and even elements should go into 2nd deque.
    *
    */

    #include <iostream>
    #include <list>
    #include <deque>
    #include <algorithm>
    #include <iterator>

    int main()
    {
    std::cout << "enter some integers: ";
    std::list<int> ilist;
    /* copy elements from std::cin into ilist */
    std::copy( (std::istream_iterator<int>( std::cin )),
    (std::istream_iterator<int>()),
    std::back_inserter( ilist ) );

    std::deque<int> deque_of_evens;
    std::deque<int> deque_of_odds;
    /* copy even elements into 1 deque and odds into the other */
    for( std::list<int>::const_iterator iter = ilist.begin();
    iter != ilist.end();
    ++iter)
    {
    if( *iter % 2 == 0 )
    {
    deque_of_evens.push_back( *iter );
    }
    else
    {
    deque_of_odds.push_back( *iter );
    }
    }



    std::cout << "\n Printing Deque of Even Integers: ";
    std::copy( deque_of_evens.begin(),
    deque_of_evens.end(),
    std::eek:stream_iterator<int>( std::cout, " " ) );

    std::cout << "\n\n Printing Deque of Odd Integers: ";
    std::copy( deque_of_odds.begin(),
    deque_of_odds.end(),
    std::eek:stream_iterator<int>( std::cout, " " ) );

    std::cout << std::endl;

    return 0;
    }


    --
    http://lispmachine.wordpress.com
     
    arnuld, Sep 25, 2007
    #1
    1. Advertising

  2. On 2007-09-25 09:59, arnuld wrote:
    > It works fine. any advice on making it better or if I can
    > improve my C++ coding skills:
    >
    > /* C++ Primer - 4/e
    > *
    > * Chapter 9 - Sequential Containers
    > * exercise 9.18 - STATEMENT
    > * Write a program to copy elements from a list of "ints"
    > * to 2 "deques". The list elements that are even should go into one deque
    > * and even elements should go into 2nd deque.
    > *
    > */
    >
    > #include <iostream>
    > #include <list>
    > #include <deque>
    > #include <algorithm>
    > #include <iterator>
    >
    > int main()
    > {
    > std::cout << "enter some integers: ";
    > std::list<int> ilist;
    > /* copy elements from std::cin into ilist */
    > std::copy( (std::istream_iterator<int>( std::cin )),
    > (std::istream_iterator<int>()),
    > std::back_inserter( ilist ) );
    >
    > std::deque<int> deque_of_evens;
    > std::deque<int> deque_of_odds;
    > /* copy even elements into 1 deque and odds into the other */
    > for( std::list<int>::const_iterator iter = ilist.begin();
    > iter != ilist.end();
    > ++iter)
    > {
    > if( *iter % 2 == 0 )
    > {
    > deque_of_evens.push_back( *iter );
    > }
    > else
    > {
    > deque_of_odds.push_back( *iter );
    > }
    > }
    >
    >
    >
    > std::cout << "\n Printing Deque of Even Integers: ";
    > std::copy( deque_of_evens.begin(),
    > deque_of_evens.end(),
    > std::eek:stream_iterator<int>( std::cout, " " ) );
    >
    > std::cout << "\n\n Printing Deque of Odd Integers: ";
    > std::copy( deque_of_odds.begin(),
    > deque_of_odds.end(),
    > std::eek:stream_iterator<int>( std::cout, " " ) );
    >
    > std::cout << std::endl;
    >
    > return 0;
    > }


    You should research the (IMO badly named) remove_copy_if algorithm and
    create a predicate to determine if the element is even or not.

    --
    Erik Wikström
     
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=, Sep 25, 2007
    #2
    1. Advertising

  3. arnuld

    Kai-Uwe Bux Guest

    Erik Wikström wrote:

    > On 2007-09-25 09:59, arnuld wrote:
    >> It works fine. any advice on making it better or if I can
    >> improve my C++ coding skills:
    >>
    >> /* C++ Primer - 4/e
    >> *
    >> * Chapter 9 - Sequential Containers
    >> * exercise 9.18 - STATEMENT
    >> * Write a program to copy elements from a list of
    >> "ints" * to 2 "deques". The list elements that are even should go into
    >> one deque * and even elements should go into 2nd deque.
    >> *
    >> */
    >>
    >> #include <iostream>
    >> #include <list>
    >> #include <deque>
    >> #include <algorithm>
    >> #include <iterator>
    >>
    >> int main()
    >> {
    >> std::cout << "enter some integers: ";
    >> std::list<int> ilist;
    >> /* copy elements from std::cin into ilist */
    >> std::copy( (std::istream_iterator<int>( std::cin )),
    >> (std::istream_iterator<int>()),
    >> std::back_inserter( ilist ) );
    >>
    >> std::deque<int> deque_of_evens;
    >> std::deque<int> deque_of_odds;
    >> /* copy even elements into 1 deque and odds into the other */
    >> for( std::list<int>::const_iterator iter = ilist.begin();
    >> iter != ilist.end();
    >> ++iter)
    >> {
    >> if( *iter % 2 == 0 )
    >> {
    >> deque_of_evens.push_back( *iter );
    >> }
    >> else
    >> {
    >> deque_of_odds.push_back( *iter );
    >> }
    >> }
    >>
    >>
    >>
    >> std::cout << "\n Printing Deque of Even Integers: ";
    >> std::copy( deque_of_evens.begin(),
    >> deque_of_evens.end(),
    >> std::eek:stream_iterator<int>( std::cout, " " ) );
    >>
    >> std::cout << "\n\n Printing Deque of Odd Integers: ";
    >> std::copy( deque_of_odds.begin(),
    >> deque_of_odds.end(),
    >> std::eek:stream_iterator<int>( std::cout, " " ) );
    >>
    >> std::cout << std::endl;
    >>
    >> return 0;
    >> }

    >
    > You should research the (IMO badly named) remove_copy_if algorithm and
    > create a predicate to determine if the element is even or not.


    And: you should implement the missing (sic!) copy_if algorithm and use the
    same predicate for the other copy job.


    Best

    Kai-Uwe Bux
     
    Kai-Uwe Bux, Sep 25, 2007
    #3
  4. arnuld

    James Kanze Guest

    On Sep 25, 11:24 am, Kai-Uwe Bux <> wrote:
    > Erik Wikström wrote:
    > > On 2007-09-25 09:59, arnuld wrote:
    > >> It works fine. any advice on making it better or if I can
    > >> improve my C++ coding skills:


    > >> /* C++ Primer - 4/e
    > >> *
    > >> * Chapter 9 - Sequential Containers
    > >> * exercise 9.18 - STATEMENT
    > >> * Write a program to copy elements from a list of
    > >> "ints" * to 2 "deques". The list elements that are even should go into
    > >> one deque * and even elements should go into 2nd deque.
    > >> *
    > >> */


    > >> #include <iostream>
    > >> #include <list>
    > >> #include <deque>
    > >> #include <algorithm>
    > >> #include <iterator>


    > >> int main()
    > >> {
    > >> std::cout << "enter some integers: ";
    > >> std::list<int> ilist;
    > >> /* copy elements from std::cin into ilist */
    > >> std::copy( (std::istream_iterator<int>( std::cin )),
    > >> (std::istream_iterator<int>()),
    > >> std::back_inserter( ilist ) );


    > >> std::deque<int> deque_of_evens;
    > >> std::deque<int> deque_of_odds;
    > >> /* copy even elements into 1 deque and odds into the other */
    > >> for( std::list<int>::const_iterator iter = ilist.begin();
    > >> iter != ilist.end();
    > >> ++iter)
    > >> {
    > >> if( *iter % 2 == 0 )
    > >> {
    > >> deque_of_evens.push_back( *iter );
    > >> }
    > >> else
    > >> {
    > >> deque_of_odds.push_back( *iter );
    > >> }


    You might replace the if with:

    (*iter % 2 == 0 ? deque_of_evens :
    deque_of_odds).push_back( *iter ) ;

    Opinions about this vary; I tend not to use ?: very much for
    lvalues, but in this case, it does draw attention to the fact
    that *all* of the elements end up in one of the two deques.

    > >> }


    > >> std::cout << "\n Printing Deque of Even Integers: ";
    > >> std::copy( deque_of_evens.begin(),
    > >> deque_of_evens.end(),
    > >> std::eek:stream_iterator<int>( std::cout, " " ) );


    > >> std::cout << "\n\n Printing Deque of Odd Integers: ";
    > >> std::copy( deque_of_odds.begin(),
    > >> deque_of_odds.end(),
    > >> std::eek:stream_iterator<int>( std::cout, " " ) );


    > >> std::cout << std::endl;
    > >> return 0;
    > >> }


    > > You should research the (IMO badly named) remove_copy_if
    > > algorithm and create a predicate to determine if the element
    > > is even or not.


    > And: you should implement the missing (sic!) copy_if algorithm
    > and use the same predicate for the other copy job.


    I'm not sure that I agree with either of these recommendations.
    Both smack of obfuscation, and forcing things just to use a
    standard (or non-standard, in the case of copy_if) algorithm.
    For a more experienced programmer, I might consider a
    boost::filter_iterator, e.g.:

    std::deque< int > evens(
    boost::make_filter_iterator< IsEven >( ilist.begin(),
    ilist.end() ),
    boost::make_filter_iterator< IsEven >( ilist.end(),
    ilist.end() ) ) ;
    std::deque< int > odds(
    boost::make_filter_iterator< IsOdd >( ilist.begin(),
    ilist.end() ),
    boost::make_filter_iterator< IsOdd >( ilist.end(),
    ilist.end() ) ) ;

    This allows correct initialization; it would even allow making
    evens and odds const. But it still requires moving the test out
    of the loop, and even out of the function. And I'm pretty sure
    that it's not the intent of the exercise.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Sep 25, 2007
    #4
  5. arnuld

    arnuld Guest

    > On Sep 25, 2:56 pm, James Kanze <> wrote:

    > You might replace the if with:
    >
    > (*iter % 2 == 0 ? deque_of_evens :
    > deque_of_odds).push_back( *iter ) ;
    >
    > Opinions about this vary; I tend not to use ?: very much for
    > lvalues, but in this case, it does draw attention to the fact
    > that *all* of the elements end up in one of the two deques.


    that's nice James (as for as my exercise is concerned ). I have
    used that construct, it make my solution look clean :)
     
    arnuld, Sep 25, 2007
    #5
  6. arnuld

    Kai-Uwe Bux Guest

    James Kanze wrote:

    > On Sep 25, 11:24 am, Kai-Uwe Bux <> wrote:
    >> Erik Wikström wrote:
    >> > On 2007-09-25 09:59, arnuld wrote:
    >> >> It works fine. any advice on making it better or if I can
    >> >> improve my C++ coding skills:

    >
    >> >> /* C++ Primer - 4/e
    >> >> *
    >> >> * Chapter 9 - Sequential Containers
    >> >> * exercise 9.18 - STATEMENT
    >> >> * Write a program to copy elements from a list of
    >> >> "ints" * to 2 "deques". The list elements that are even should go
    >> >> into one deque * and even elements should go into 2nd deque.
    >> >> *
    >> >> */

    >
    >> >> #include <iostream>
    >> >> #include <list>
    >> >> #include <deque>
    >> >> #include <algorithm>
    >> >> #include <iterator>

    >
    >> >> int main()
    >> >> {
    >> >> std::cout << "enter some integers: ";
    >> >> std::list<int> ilist;
    >> >> /* copy elements from std::cin into ilist */
    >> >> std::copy( (std::istream_iterator<int>( std::cin )),
    >> >> (std::istream_iterator<int>()),
    >> >> std::back_inserter( ilist ) );

    >
    >> >> std::deque<int> deque_of_evens;
    >> >> std::deque<int> deque_of_odds;
    >> >> /* copy even elements into 1 deque and odds into the other */
    >> >> for( std::list<int>::const_iterator iter = ilist.begin();
    >> >> iter != ilist.end();
    >> >> ++iter)
    >> >> {
    >> >> if( *iter % 2 == 0 )
    >> >> {
    >> >> deque_of_evens.push_back( *iter );
    >> >> }
    >> >> else
    >> >> {
    >> >> deque_of_odds.push_back( *iter );
    >> >> }

    >
    > You might replace the if with:
    >
    > (*iter % 2 == 0 ? deque_of_evens :
    > deque_of_odds).push_back( *iter ) ;
    >
    > Opinions about this vary; I tend not to use ?: very much for
    > lvalues, but in this case, it does draw attention to the fact
    > that *all* of the elements end up in one of the two deques.
    >
    >> >> }

    >
    >> >> std::cout << "\n Printing Deque of Even Integers: ";
    >> >> std::copy( deque_of_evens.begin(),
    >> >> deque_of_evens.end(),
    >> >> std::eek:stream_iterator<int>( std::cout, " " ) );

    >
    >> >> std::cout << "\n\n Printing Deque of Odd Integers: ";
    >> >> std::copy( deque_of_odds.begin(),
    >> >> deque_of_odds.end(),
    >> >> std::eek:stream_iterator<int>( std::cout, " " ) );

    >
    >> >> std::cout << std::endl;
    >> >> return 0;
    >> >> }

    >
    >> > You should research the (IMO badly named) remove_copy_if
    >> > algorithm and create a predicate to determine if the element
    >> > is even or not.

    >
    >> And: you should implement the missing (sic!) copy_if algorithm
    >> and use the same predicate for the other copy job.

    >
    > I'm not sure that I agree with either of these recommendations.
    > Both smack of obfuscation, and forcing things just to use a
    > standard (or non-standard, in the case of copy_if) algorithm.


    I have a great deal of sympathy for that sentiment. Functors tend to move
    code from the place where you would like to see it to some other place.
    That is generally not so good.


    > For a more experienced programmer, I might consider a
    > boost::filter_iterator, e.g.:
    >
    > std::deque< int > evens(
    > boost::make_filter_iterator< IsEven >( ilist.begin(),
    > ilist.end() ),
    > boost::make_filter_iterator< IsEven >( ilist.end(),
    > ilist.end() ) ) ;
    > std::deque< int > odds(
    > boost::make_filter_iterator< IsOdd >( ilist.begin(),
    > ilist.end() ),
    > boost::make_filter_iterator< IsOdd >( ilist.end(),
    > ilist.end() ) ) ;
    >
    > This allows correct initialization; it would even allow making
    > evens and odds const. But it still requires moving the test out
    > of the loop, and even out of the function.

    [snip]

    In a case like this, I like lambda:

    std::remove_copy_if( ilist.begin(), ilist.end(),
    std::back_inserter( deque_of_evens ),
    _1 % 2 != 0 );

    std::remove_copy_if( ilist.begin(), ilist.end(),
    std::back_inserter( deque_of_odds ),
    _1 % 2 == 0 );

    (yet, I would prefer copy_if :)

    I agree, though, that cases where lambda is this concise are rare. But
    compared to using std::binder..., std::modulus, ... lambda is great.


    Best

    Kai-Uwe Bux
     
    Kai-Uwe Bux, Sep 25, 2007
    #6
  7. arnuld

    arnuld Guest

    > On Sep 25, 3:23 pm, Kai-Uwe Bux <> wrote:

    > In a case like this, I like lambda:
    >
    > std::remove_copy_if( ilist.begin(), ilist.end(),
    > std::back_inserter( deque_of_evens ),
    > _1 % 2 != 0 );
    >
    > std::remove_copy_if( ilist.begin(), ilist.end(),
    > std::back_inserter( deque_of_odds ),
    > _1 % 2 == 0 );
    >


    ok, that's nice :)

    and i did not get that _1 %2, I know it checks for even and odd
    numbers but what exactly that "underscore 1" means: _1 %2
     
    arnuld, Sep 25, 2007
    #7
  8. arnuld

    Kai-Uwe Bux Guest

    arnuld wrote:

    >> On Sep 25, 3:23 pm, Kai-Uwe Bux <> wrote:

    >
    >> In a case like this, I like lambda:
    >>
    >> std::remove_copy_if( ilist.begin(), ilist.end(),
    >> std::back_inserter( deque_of_evens ),
    >> _1 % 2 != 0 );
    >>
    >> std::remove_copy_if( ilist.begin(), ilist.end(),
    >> std::back_inserter( deque_of_odds ),
    >> _1 % 2 == 0 );
    >>

    >
    > ok, that's nice :)
    >
    > and i did not get that _1 %2, I know it checks for even and odd
    > numbers but what exactly that "underscore 1" means: _1 %2



    That's the magic of expression templates. If you are interested, you can
    have a look at my posting

    http://groups.google.com/group/comp.lang.c /browse_frm/thread/739246bc9aef054e/09422ea883a2b151

    where I explain how one can about implementing something like that. Be
    warned, however: it takes about 600 lines of code (and 300 lines of
    comments) to make that _1 work (and that is just a proof of concept!).

    Luckily, it already has been done and is in boost.


    Best

    Kai-Uwe Bux
     
    Kai-Uwe Bux, Sep 25, 2007
    #8
  9. arnuld

    arnuld Guest

    > On Sep 25, 2:56 pm, James Kanze <> wrote:
    > I'm not sure that I agree with either of these recommendations.
    > Both smack of obfuscation, and forcing things just to use a
    > standard (or non-standard, in the case of copy_if) algorithm.
    > For a more experienced programmer, I might consider a
    > boost::filter_iterator, e.g.:
    >
    > std::deque< int > evens(
    > boost::make_filter_iterator< IsEven >( ilist.begin(),
    > ilist.end() ),
    > boost::make_filter_iterator< IsEven >( ilist.end(),
    > ilist.end() ) ) ;
    > std::deque< int > odds(
    > boost::make_filter_iterator< IsOdd >( ilist.begin(),
    > ilist.end() ),
    > boost::make_filter_iterator< IsOdd >( ilist.end(),
    > ilist.end() ) ) ;
    >
    > This allows correct initialization; it would even allow making
    > evens and odds const. But it still requires moving the test out
    > of the loop, and even out of the function. And I'm pretty sure
    > that it's not the intent of the exercise.


    I am trying this but can not copile my program with that without
    errors. I am using remove_copy_if as suggested by Kai-Uwe Bux
    (remember the _1 ;-)

    but still I am interested in this use of boost library. I have copied
    the code you wrote but then I am not able to get what to do to
    make use of this make_filter_iterator.

    any explanation ?
     
    arnuld, Sep 25, 2007
    #9
  10. arnuld

    James Kanze Guest

    On Sep 25, 12:23 pm, Kai-Uwe Bux <> wrote:
    > James Kanze wrote:


    [...]
    > >> And: you should implement the missing (sic!) copy_if algorithm
    > >> and use the same predicate for the other copy job.


    > > I'm not sure that I agree with either of these recommendations.
    > > Both smack of obfuscation, and forcing things just to use a
    > > standard (or non-standard, in the case of copy_if) algorithm.


    > I have a great deal of sympathy for that sentiment. Functors
    > tend to move code from the place where you would like to see
    > it to some other place. That is generally not so good.


    It depends. If you can supply a good, explicit name for the
    function, and it is a "pure" function, not depending on any
    local variables, it's not that bad. If you can reasonably
    expect to use the function elsewhere, it's even good. I'd say
    that his case meets the first criteron, but not really the
    second. So it's not too bad, but I still prefer the test in an
    explicit loop. (There's also the question of how much you're
    throwing at the OP at a time. He IS working his way through a
    tutorial text, and shouldn't be expected to handle everything at
    once. Each thing in its time.)

    > > For a more experienced programmer, I might consider a
    > > boost::filter_iterator, e.g.:


    > > std::deque< int > evens(
    > > boost::make_filter_iterator< IsEven >( ilist.begin(),
    > > ilist.end() ),
    > > boost::make_filter_iterator< IsEven >( ilist.end(),
    > > ilist.end() ) ) ;
    > > std::deque< int > odds(
    > > boost::make_filter_iterator< IsOdd >( ilist.begin(),
    > > ilist.end() ),
    > > boost::make_filter_iterator< IsOdd >( ilist.end(),
    > > ilist.end() ) ) ;


    > > This allows correct initialization; it would even allow
    > > making evens and odds const. But it still requires moving
    > > the test out of the loop, and even out of the function.


    > [snip]


    > In a case like this, I like lambda:


    > std::remove_copy_if( ilist.begin(), ilist.end(),
    > std::back_inserter( deque_of_evens ),
    > _1 % 2 != 0 );


    > std::remove_copy_if( ilist.begin(), ilist.end(),
    > std::back_inserter( deque_of_odds ),
    > _1 % 2 == 0 );


    > (yet, I would prefer copy_if :)


    > I agree, though, that cases where lambda is this concise are
    > rare. But compared to using std::binder..., std::modulus, ...
    > lambda is great.


    If we had a real lambda, it would be great (although as you
    point out, in this particular case, boost::lambda works like a
    real lambda). Ideally, even, we'd have a lambda which resolved
    to a class which could be used to instantiate a template like
    boost::make_filter_iterator, so I could replace IsEven and IsOdd
    in my example.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Sep 26, 2007
    #10
  11. arnuld

    James Kanze Guest

    On Sep 25, 8:11 pm, arnuld <> wrote:
    > > On Sep 25, 2:56 pm, James Kanze <> wrote:
    > > I'm not sure that I agree with either of these recommendations.
    > > Both smack of obfuscation, and forcing things just to use a
    > > standard (or non-standard, in the case of copy_if) algorithm.
    > > For a more experienced programmer, I might consider a
    > > boost::filter_iterator, e.g.:


    > > std::deque< int > evens(
    > > boost::make_filter_iterator< IsEven >( ilist.begin(),
    > > ilist.end() ),
    > > boost::make_filter_iterator< IsEven >( ilist.end(),
    > > ilist.end() ) ) ;
    > > std::deque< int > odds(
    > > boost::make_filter_iterator< IsOdd >( ilist.begin(),
    > > ilist.end() ),
    > > boost::make_filter_iterator< IsOdd >( ilist.end(),
    > > ilist.end() ) ) ;


    > > This allows correct initialization; it would even allow making
    > > evens and odds const. But it still requires moving the test out
    > > of the loop, and even out of the function. And I'm pretty sure
    > > that it's not the intent of the exercise.


    > I am trying this but can not copile my program with that without
    > errors. I am using remove_copy_if as suggested by Kai-Uwe Bux
    > (remember the _1 ;-)


    Do you have Boost correctly installed? Are you including all of
    the necessary Boost header files, and passing the necessary
    options to the compiler so that it finds them (and the Boost
    library, although I don't think either Kai-Uwe's suggestion or
    mine actually require linking against the library).

    > but still I am interested in this use of boost library. I have
    > copied the code you wrote but then I am not able to get what
    > to do to make use of this make_filter_iterator.


    > any explanation ?


    The real explanation is that you're jumping too far ahead of
    where you are in the learning cycle. Learn the basics first;
    there's time enough for Boost later.

    Other than that, of course, you have to ensure that Boost is
    correctly installed, that the compiler is passed all of the
    necessary options, etc. (Under Unix, for example, you'll need
    at least an additional -I option, and perhaps also an additional
    -l. With VC++, that's a /I option and an additional library to
    link against.) But seriously: I prefixed my suggestion with
    "For a more experienced programmer". I did so for a reason.
    Don't worry about it yet.

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Sep 26, 2007
    #11
  12. arnuld

    arnuld Guest

    > On Wed, 26 Sep 2007 01:50:36 -0700, James Kanze wrote:

    > Do you have Boost correctly installed?


    yes.

    > Are you including all of
    > the necessary Boost header files, and passing the necessary
    > options to the compiler so that it finds them (and the Boost
    > library, although I don't think either Kai-Uwe's suggestion or
    > mine actually require linking against the library).


    don't know, I just used "#include <boost>" and GCC complained then.


    > The real explanation is that you're jumping too far ahead of
    > where you are in the learning cycle. Learn the basics first;
    > there's time enough for Boost later.


    > .....[SNIP]....


    > But seriously: I prefixed my suggestion with
    > "For a more experienced programmer". I did so for a reason.
    > Don't worry about it yet.


    Ok, I understood :) for now, I will just use <algorithm>


    -- arnuld
    http://lispmachine.wordpress.com
     
    arnuld, Sep 28, 2007
    #12
  13. On 2007-09-28 15:39, arnuld wrote:
    >> On Wed, 26 Sep 2007 01:50:36 -0700, James Kanze wrote:

    >
    >> Do you have Boost correctly installed?

    >
    > yes.
    >
    >> Are you including all of
    >> the necessary Boost header files, and passing the necessary
    >> options to the compiler so that it finds them (and the Boost
    >> library, although I don't think either Kai-Uwe's suggestion or
    >> mine actually require linking against the library).

    >
    > don't know, I just used "#include <boost>" and GCC complained then.


    I'm not a boost expert, but including <boost> is probably not the right
    way, you should include <boost/iterator/filter_iterator.hpp> and you
    might need to include some other headers too.

    --
    Erik Wikström
     
    =?UTF-8?B?RXJpayBXaWtzdHLDtm0=?=, Sep 28, 2007
    #13
  14. arnuld

    James Kanze Guest

    On Sep 28, 3:39 pm, arnuld <> wrote:

    [...]
    > > Are you including all of
    > > the necessary Boost header files, and passing the necessary
    > > options to the compiler so that it finds them (and the Boost
    > > library, although I don't think either Kai-Uwe's suggestion or
    > > mine actually require linking against the library).


    > don't know, I just used "#include <boost>" and GCC complained then.


    That is surely wrong. But one of the really big weaknesses of
    the Boost documentation is that they don't tell you what headers
    you need. (Probably <boost/iterator.hpp>, here. Or perhaps
    some special header for the specific adaptor. I'd have to
    experiment myself to find out.)

    > > The real explanation is that you're jumping too far ahead of
    > > where you are in the learning cycle. Learn the basics first;
    > > there's time enough for Boost later.
    > > .....[SNIP]....
    > > But seriously: I prefixed my suggestion with
    > > "For a more experienced programmer". I did so for a reason.
    > > Don't worry about it yet.


    > Ok, I understood :) for now, I will just use <algorithm>


    I think that's the goal of the exercise:).

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Sep 28, 2007
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff Schwab

    vector, list and deque

    Jeff Schwab, Jan 2, 2004, in forum: C++
    Replies:
    4
    Views:
    7,811
    Rob Williscroft
    Jan 3, 2004
  2. Travis L Spencer
    Replies:
    3
    Views:
    375
    Travis L Spencer
    Jan 21, 2005
  3. Russell Warren
    Replies:
    5
    Views:
    438
    Tim Peters
    May 2, 2006
  4. Adam Hartshorne
    Replies:
    2
    Views:
    387
    Nitin Motgi
    Jan 27, 2006
  5. Replies:
    6
    Views:
    140
    Öö Tiib
    Mar 3, 2014
Loading...

Share This Page