X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/7b138f8b1ed3e8816eda5cb26deb71fe81b4087a..950b9d175a7966b91adf53b74745ce4e6e5da5f9:/include/xbt/utility.hpp diff --git a/include/xbt/utility.hpp b/include/xbt/utility.hpp index 09d8db40bf..df3fbf4ccf 100644 --- a/include/xbt/utility.hpp +++ b/include/xbt/utility.hpp @@ -1,14 +1,34 @@ -/* Copyright (c) 2016. The SimGrid Team. +/* Copyright (c) 2016-2018. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ +#ifndef XBT_UTILITY_HPP +#define XBT_UTILITY_HPP + #include namespace simgrid { namespace xbt { +/** @brief Comparator class for using with std::priority_queue or boost::heap. + * + * Compare two std::pair by their first element (of type double), and return true when the first is greater than the + * second. Useful to have priority queues with the smallest element on top. + */ +template class HeapComparator { +public: + bool operator()(const Pair& a, const Pair& b) const { return a.first > b.first; } +}; + +/** @brief Erase an element given by reference from a boost::intrusive::list. + */ +template inline void intrusive_erase(List& list, Elem& elem) +{ + list.erase(list.iterator_to(elem)); +} + // integer_sequence and friends from C++14 // We need them to implement `apply` from C++17. @@ -46,7 +66,7 @@ class integer_sequence { namespace bits { template struct make_integer_sequence : - public make_integer_sequence + make_integer_sequence {}; template struct make_integer_sequence { @@ -78,3 +98,4 @@ static_assert(std::is_same< index_sequence_for, make_index_seq } } +#endif