Boost logo

Boost Users :

From: Pavol Droba (droba_at_[hidden])
Date: 2005-07-08 01:35:55


Hi,

On Thu, Jul 07, 2005 at 09:55:37PM -0700, Duane Murphy wrote:
> I'm trying to define a custom sequence for use by the replace_all()
> function of boost::string::algo. I'm hitting an error that I am not able
> to decipher the cause of.
>
> In the Finder concept check in find_format.hpp (Line 238), I'm getting
> two errors:
> Error : illegal template argument(s)
> (point of instantiation: 'SpecifyItem(const unsigned char *, const
> unsigned char *, bool)')
> (instantiating: 'boost::algorithm::replace_all<sequence, const
> unsigned char *, const unsigned char *>(sequence &, const unsigned char
> *const &, const unsigned char *const &)')
> (instantiating: 'boost::algorithm::find_format_all<sequence,
> boost::algorithm::detail::first_finderF<const unsigned char *,
> boost::algorithm::is_equal>, boost::a
> lgorithm::detail::const_formatF<const unsigned char *>>(sequence &,
> boost::algorithm::detail::first_finderF<const unsigned char *,
> boost::algorithm::is_equal>, boost::a
> lgorithm::detail::const_formatF<const unsigned char *>)')
> find_format.hpp line 238 BOOST_STRING_TYPENAME
> const_iterator_of<SequenceT>::type> >();
>
> Error : '(' expected
> (point of instantiation: 'SpecifyItem(const unsigned char *, const
> unsigned char *, bool)')
> (instantiating: 'boost::algorithm::replace_all<sequence, const
> unsigned char *, const unsigned char *>(sequence &, const unsigned char
> *const &, const unsigned char *const &)')
> (instantiating: 'boost::algorithm::find_format_all<sequence,
> boost::algorithm::detail::first_finderF<const unsigned char *,
> boost::algorithm::is_equal>, boost::a
> lgorithm::detail::const_formatF<const unsigned char *>>(sequence &,
> boost::algorithm::detail::first_finderF<const unsigned char *,
> boost::algorithm::is_equal>, boost::a
> lgorithm::detail::const_formatF<const unsigned char *>)')
> find_format.hpp line 238 BOOST_STRING_TYPENAME
> const_iterator_of<SequenceT>::type> >();
>
>
> The sequence I am defining wraps a Macintosh style Pascal string. (For
> those not in the know, these are a string where the first byte is the
> length. The character type is also unsigned char.)
>
> I am defining the sequence called sequence:
>
> class sequence
> {
> public:
> sequence() {}
>
> sequence( unsigned char* in_sequence )
> : sequence( in_sequence ) {}
>
> typedef unsigned char value_type;
> typedef std::ptrdiff_t difference_type;
> typedef std::size_t size_type;
> typedef unsigned char* iterator;
> typedef const unsigned char* const_iterator;
>
> iterator begin() { return &sequence[1]; }
> const_iterator begin() const { return &sequence[1]; }
>
> iterator end() { return &sequence[ sequence[0] ]; }
> const_iterator end() const { return &sequence[ sequence[0] ]; }
>
> private:
> unsigned char* sequence;
> };
>
> This isn't complete, but I thought I could get a little farther than
> this or at least understand what I am missing from the definition that
> this concept check doesn't fail.
>
> I am using it like this:
>
> void SpecifyItem( unsigned string* in_pascal_string )
> {
> sequence seq( in_pascal_string );
> const unsigned char* find_this = "\pa";
> const unsigned char* replace_with = "\pb";
> boost::algorithm::replace_all( seq, find_this, replace_with );
> }
>
> I also don't have a copy of the spec to understand all of the
> requirements for a sequence, so I was shooting in the dark emulating a
> vector to see how for I could get. I expected to get a little farther. :-)
>
> Thanks for any tips,
>
> ...Duane
>
 
First off all, your sequence satisfies only range requirements. This is sufficient if
you want to access the content of the sequence but it is not if you want to manipulate it.

I don't know if you have access to C++ standard. The sequence requirement are defined there.

Let me make a small digest.
All mutating and sequence-based copy variants of algorithms in the string algo library require
the sequence to have a contructor, that accepts two iterators.
In addition, replace algorithms need insert and replace member function.

So you need to add at least following members:

template<typename OtherIt>
sequence(OtherIt From, OtherIt To);

template<typename OtherIt>
void insert(iterator Where, OtherIt From, OtherIt To);

iterator erase(iterator From, iterator To);

There might be something else, but this is one of the problems for sure.

Regards,
Pavol


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net