Example #1
0
  void list_algorithms<ContainerTraits, Ovr>::sort (container &c)
  {
    typedef typename self_type::container_traits::value_traits_type
      vtraits;

    typedef typename vtraits::less comparison;
#if BOOST_WORKAROUND (BOOST_MSVC, == 1200)
    // MSVC6 doesn't have a templated sort member in list, so we just
    // use the parameterless version. This gives the correct behaviour
    // provided that value_traits_type::less is exactly
    // std::less<value_type>. It would be possible to support
    // std::greater<T> (the only other overload of list::sort in
    // MSVC6) with some additional work.
    BOOST_STATIC_ASSERT(
        (::boost::is_same<comparison, std::less<value_type> >::value));
    c.sort ();
#else
    c.sort (comparison());
#endif
  }
Example #2
0
File: main.cpp Project: CCJY/coliru
double median(container l) {
    typedef container::size_type l_sz;
	
	l_sz size = l.size();
	if (size == 0)
		throw std::domain_error("median of an empty list");
	
	l.sort();

    std::size_t mid = size / 2;
    const_iter it = l.begin();
    
    for(std::size_t i = 0; i != mid; ++i) {
        ++it;
    }
    
    if (size % 2 == 0) {
        const_iter base = it--;
        return (*base + *it) / 2;
    }
    else {
        return *it;
    }
}