Browse Source

Made the version() functions constexpr.

Not sure why it wasn't like that before.
pull/141/head
Vladimír Vondruš 10 years ago
parent
commit
628201946b
  1. 12
      src/Magnum/Test/VersionTest.cpp
  2. 5
      src/Magnum/Version.h

12
src/Magnum/Test/VersionTest.cpp

@ -50,17 +50,21 @@ VersionTest::VersionTest() {
void VersionTest::fromNumber() {
#ifndef MAGNUM_TARGET_GLES
CORRADE_COMPARE(version(4, 3), Version::GL430);
constexpr const Version v = version(4, 3);
CORRADE_COMPARE(v, Version::GL430);
#else
CORRADE_COMPARE(version(3, 0), Version::GLES300);
constexpr const Version v = version(3, 0);
CORRADE_COMPARE(v, Version::GLES300);
#endif
}
void VersionTest::toNumber() {
#ifndef MAGNUM_TARGET_GLES
CORRADE_COMPARE(version(Version::GL430), std::make_pair(4, 3));
constexpr const auto v = version(Version::GL430);
CORRADE_COMPARE(v, std::make_pair(4, 3));
#else
CORRADE_COMPARE(version(Version::GLES300), std::make_pair(3, 0));
constexpr const auto v = version(Version::GLES300);
CORRADE_COMPARE(v, std::make_pair(3, 0));
#endif
}

5
src/Magnum/Version.h

@ -100,12 +100,11 @@ enum class Version: Int {
};
/** @brief Enum value from major and minor version number */
inline Version version(Int major, Int minor) {
constexpr Version version(Int major, Int minor) {
return Version(major*100 + minor*10);
}
/** @brief Major and minor version number from enum value */
inline std::pair<Int, Int> version(Version version) {
constexpr std::pair<Int, Int> version(Version version) {
return {Int(version)/100, (Int(version)%100)/10};
}

Loading…
Cancel
Save