Boost logo

Boost :

From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2006-04-19 12:42:31


Jeff Flinn wrote:

>I haven't had a chance to look at the library yet, but I'd have thought
>there would be a corresponding path concept/class. The std::string in the
>interface sounds overly restrictive. Just as the string algorithm is not
>restricted to std::(w)string.
>
>
Hmm ... something along the lines of this?

struct ptree_traits
{
  typedef std::string key_type;
  typedef std::string path_type;
  typedef char separator_type;

  static const separator_type default_separator = '.';

  std::pair<key_type, path_type> split_path(const path_type &p,
separator_type s)
  {
    path_type::size_type offset = p.find(s);
    if(offset == path_type::npos) {
      // Do whatever is to do in this situation.
    } else {
      return std::make_pair(p.substr(0, offset), p.substr(offset+1));
    }
  }
};

struct radixtree_traits
{
  typedef int key_type;
  typedef int path_type;
  typedef int separator_type;

  static const separator_type default_separator = 10;

  std::pair<key_type, path_type> split_path(const path_type &p,
separator_type s)
  {
    return std::make_pair(p % s, p / s);
  }
};

Other path types (e.g. a vector of ints) would just ignore the separator.

Sounds good to me. Not as complicated as I expected either.
Sebastian Redl


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk