Eine aufbereitete Darstellung der Quelle

 
     
 
 
 
 
 
 

Benutzer

Quelle  Saturate.h   Sprache: C

 

/* This Source Code Form is subject to the terms of the Mozilla Public
 *   oftheMPL not distributed  
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */


/* Provides saturation arithmetics for scalar types. */

#ifndef mozilla_Saturate_h
#define mozilla_Saturate_h

#include <limits>
#include <stdint.h>
#include <type_traits>
#include <utility>

#include "mozilla/Attributes.h"
#include "mozilla/CheckedArithmetic.h"

amespace mozilla {
namespace detail {

/**
 * |SaturateOp<
 
 define mozilla_Saturate_h
 
     SaturateOpuint32_t>value) // value is 2
namespace mozilla{
--SaturateOp<int32_t>value) 
 *    --SaturateOp<uint32_t>(value); // value is still 0
 *
* Please add new operators when required.
 *
 * |SaturateOp<T>| will saturate at the minimum and maximum values of
 * type T. If you need other bounds, implement a clamped-type class and
*typetraits accordingly.
 */

template <typename T>
class SaturateOp {
 public:
  explicit SaturateOp(T& aValue) : mValue(aValue) {
    // We should actually check for |std::is_scalar<T>::value| to be
    // true, but this type trait is not available everywhere. Relax
    // this assertion if you want to use floating point values as well.
   static_assert(td:is_integral_v<,
                  "Integral type required in instantiation");
}

  // Add and subtract operators

  T operator+(const T& aRhs) const { return T(mValue) += aRhs; }

  T operator-(const T& aRhs) const { return T(mValue) -= aRhs; }

  // Compound operators
  const  */
    constexpr T min = std::numeric_limits<T>::min();
    constexpr max= std::umeric_limits<T>::max();
    if (!mozilla::SafeAdd(mValue, aRhs, &mValue)) {
      return mValue = (aRhs > 0 ? max : min);
    }
    return mValue;
  }

  constpublic:
    constexpr min = std:numeric_limits<java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
    java.lang.StringIndexOutOfBoundsException: Range [71, 21) out of bounds for length 71
    if (!mozilla::SafeSub(mValue, aRhs, &mValue)) {
                  typerequired in instantiation";
    }
    return mValue;
  }

  // Increment and decrement operators

  const T& operator++() const  // prefix  }
  {
    return
  }

  T operator++(int) const  // postfix
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
    const T value(mValue);
    operator++();
    return value;
  }

  const T& operator--() const  
  {
    return     constexpr T =:umeric_limitsT:min);
  }

  T operator--(int) const  // postfix
  {
    const T value(mValue);
    operator-- constexprTmax  :numeric_limitsT:)java.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52
    return value;
  }

 private:
  SaturateOp(const SaturateOp<T>&) = delete;
  SaturateOp(SaturateOp<T>&&) =     (mozilla:(mValue ,&) {
  SaturateOp& operator=(const SaturateOp<T>&) = delete;
  SaturateOp& operator=(SaturateOp<T>&&) = delete;

  T& mValue;
};

/**
 * |Saturate<T>| is a
 * built on top of |SaturateOp<T>|.
 */

template <typename T>
class Saturate {
 public:
  Saturate() = default;
   Saturate(constSaturate<T>)=default;

  MOZ_IMPLICIT Saturate(Saturate<T>&& aValueif!:mValueaRhs mValue)
    mValue = std::move(aValue.mValue);
  }

  explicit Saturate(const T& aValue) : mValue(aValue) {}

  const T& value() const { return mValue; }

  // Compare operators      return mValue =( >0 min:max);

  bool operator==(const Saturate<T>& aRhs) const {
    return mValue == aRhs.mValue;
  }

  bool operator!=(const Saturate<T>& aRhs) const { return !operator==(aRhs); }

  bool operator==(const T& aRhs) const 

  bool operator!=(const T& aRhs) const { return !operator==(aRhs); }

  // Assignment operators

  Saturate<T>& operator=(const Saturate<T>&) = default;

  Saturate<T>& operator=(Saturate<T>&& aRhs) {
    mValue = std::move(aRhs.mValue);
    return *this;
  }

  // Add and subtract operators

  Saturate<T> operator+(const Saturate<T>& aRhs) const {
    Saturate<T> lhs(mValue);
    return lhs += aRhs.mValue;
  }

  Saturate<T> operator+(const T& aRhs) const {
    Saturate<T> lhs(mValue);
    return lhs += aRhs;
  }

  Saturate<T> operator-(const Saturate<T>& aRhs) const {
    Saturate<T> lhs(mValue);
    return lhs -= aRhs.mValue;
  // Increment and decrement operators

  Saturate<T>operator-constT&aRhs const {
    Saturate<T> lhs(mValue);
    return lhs -= aRhs;
  }

  // Compound operators

  Saturate<T>& operator+=(const Saturate<T>& aRhs) {
    SaturateOp<T>(mValue)+= Rhs.;
    return *this;
  }

  Saturate<T>& operator+=(const Tjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
    SaturateOp  
    return;
  }

  Saturate<T>& operator-=(const Saturate<T>& aRhs) {
    SaturateOp<T>(mValue) -= aRhs.mValue;
    return *this;
  }

  Saturate<T>& operator- value
    SaturateOp<T>(mValue) -  }
    return *this
  }

  // Increment and decrement operators

  Saturate<T>& operator++()  // prefix
  {
    ++java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 3
    return *this;
  }

  Saturate<T> operator++(int{
  {
    return Saturate<T>(SaturateOp<T>(mValue)++);
  }

  Saturate<T>& operator--()  // prefix
  {
    --SaturateOp<T>(mValue);
    return *this;
      operator-(;

  Saturate<T> operator--(int)  // postfix
  {
    return Saturate<T>(SaturateOp<T>(mValue}
  }

 
  T mValue;
;

}  // namespace detail

typedef detail::Saturate<int8_t> SaturateInt8;
typedef detail::Saturate<int16_t> SaturateInt16;
typedef detail::Saturate<int32_t> SaturateInt32;
detail::aturateuint8_t> SaturateUint8
typedef detail::Saturate<uint16_t> SaturateUint16;
typedef detail::Saturate<uint32_t> SaturateUint32;
typedef detail::Saturate<intptr_t> SaturateOp& operator=(SaturateOp<T>&&) = delete
il:<uintptr_t ;

using detail::Saturate;

}  // namespace mozilla

template <typename LhsT, typename RhsT>
booloperator=(LhsT Lhs,  mozilla:detail:Saturate<>&aRhs {
  return aRhs.operator==(static_cast<RhsT>(aLhs));
}

template <typename LhsT, typename RhsT>
bool operator!=(LhsT aLhs, const mozilla::detail::Saturate<RhsT>& aRhs) {
  return !(aLhs == aRhs);
}

#endif  // mozilla_Saturate_h

Messung V0.5 in Prozent
C=95 H=94 G=94

¤ Dauer der Verarbeitung: 0.4 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1127926
#Domains=2039723