123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- #ifndef UTILS_H_KEPMRPBH
- #define UTILS_H_KEPMRPBH
- #include <string>
- #include <vector>
- #include <boost/filesystem.hpp>
- namespace fs = boost::filesystem;
- namespace YouCompleteMe {
- bool AlmostEqual( double a, double b );
- std::string ReadUtf8File( const fs::path &filepath );
- void WriteUtf8File( const fs::path &filepath, const std::string &contents );
- template <class Container, class Key>
- typename Container::mapped_type &
- GetValueElseInsert( Container &container,
- const Key &key,
- const typename Container::mapped_type &value ) {
- return container.insert( typename Container::value_type( key, value ) )
- .first->second;
- }
- template <class Container, class Key>
- bool ContainsKey( Container &container, const Key &key ) {
- return container.find( key ) != container.end();
- }
- template <class Container, class Key>
- typename Container::mapped_type
- FindWithDefault( Container &container,
- const Key &key,
- const typename Container::mapped_type &value ) {
- typename Container::const_iterator it = container.find( key );
- return it != container.end() ? it->second : value;
- }
- template <class Container, class Key>
- bool Erase( Container &container, const Key &key ) {
- typename Container::iterator it = container.find( key );
- if ( it != container.end() ) {
- container.erase( it );
- return true;
- }
- return false;
- }
- }
- #endif
|