Boost logo

Boost :

From: Neal D. Becker (nbecker_at_[hidden])
Date: 2004-09-15 10:59:46


This handy little item, lvalue_cast, would make a useful addition to boost. I
didn't write it, and I don't recall who did.

template<class T>
inline T& lvalue_cast (const T& rvalue) {
  return const_cast<T&> (rvalue);
}

Example usage:

#include <vector>
#include <boost/range.hpp>

template<class T>
inline T& lvalue_cast (const T& rvalue) {
  return const_cast<T&> (rvalue);
}

template<typename in_cont_t>
int F (in_cont_t & in) {
  return 2;
}

int main() {
  std::vector<int> v (4);
  F (lvalue_cast (boost::make_iterator_range (v.begin(), v.end()))); << OK
  F (boost::make_iterator_range (v.begin(), v.end())); << error!
}

-- 
Please AVOID sending me WORD, EXCEL or POWERPOINT attachments.
See http://www.fsf.org/philosophy/no-word-attachments.html

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