tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Literals.h (1092B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 /* Helpers for units on integer literals. */
      8 
      9 #ifndef mozilla_Literals_h
     10 #define mozilla_Literals_h
     11 
     12 #include <cstddef>
     13 
     14 // User-defined literals to make constants more legible.  Use them by
     15 // appending them to literals such as:
     16 //
     17 // size_t page_size = 4_KiB;
     18 //
     19 constexpr size_t operator""_KiB(unsigned long long int aNum) {
     20  return size_t(aNum) * 1024;
     21 }
     22 
     23 constexpr size_t operator""_KiB(long double aNum) {
     24  return size_t(aNum * 1024);
     25 }
     26 
     27 constexpr size_t operator""_MiB(unsigned long long int aNum) {
     28  return size_t(aNum) * 1024_KiB;
     29 }
     30 
     31 constexpr size_t operator""_MiB(long double aNum) {
     32  return size_t(aNum * 1024_KiB);
     33 }
     34 
     35 constexpr double operator""_percent(long double aPercent) {
     36  return double(aPercent) / 100;
     37 }
     38 
     39 #endif /* ! mozilla_Literals_h */