libcruft-util/annotation.hpp

35 lines
645 B
C++

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright 2011 Danny Robson <danny@nerdcruft.net>
*/
#ifndef __UTIL_ANNOTATION_HPP
#define __UTIL_ANNOTATION_HPP
template <typename T>
constexpr inline
bool
likely (T &&t)
{ return __builtin_expect (!!t, true); }
template <typename T>
constexpr inline
bool
unlikely (T &&t)
{ return __builtin_expect (!!t, false); }
constexpr inline
long
expect (long val, long typical)
{
return __builtin_expect (val, typical);
}
#endif