Show misc.h syntax highlighted
/***************************************************************************
misc.h
-------------------
begin : Wed May 12 2004
copyright : (C) 2004 by Brendon Higgins
email : freepop-devel@lists.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef MISC_H_INCLUDED
#define MISC_H_INCLUDED
#include <boost/optional.hpp>
#include <stdexcept>
/**
* Four-way minimum.
*/
template <typename T>
T min(const T& a, const T& b, const T& c, const T& d) {
const T* e;
const T* f;
if (a < b) e = &a;
else e = &b;
if (c < d) f = &c;
else f = &d;
if (*e < *f) return *e;
else return *f;
}
/**
* Lookup something from a map, return optionally.
*/
template <typename T>
boost::optional<typename T::mapped_type> lookup(const T& map,
const typename T::key_type& key) {
typename T::const_iterator i = map.find(key);
if (i != map.end()) return i->second;
return boost::optional<typename T::mapped_type>();
}
#endif /* ndef MISC_H_INCLUDED */
See more files for this project here