Sha256: 3ec9452ca2591ad17253aa8efa234ea03d483f6e57dafdd303f1397c2fab2d92

Contents?: true

Size: 821 Bytes

Versions: 1

Compression:

Stored size: 821 Bytes

Contents

// -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil -*-

/**
 * @file   staticlog.h
 * @brief  Statically returns the log (base 2) of a value.
 * @author Emery Berger <http://www.cs.umass.edu/~emery>
 * @note   Copyright (C) 2005 by Emery Berger, University of Massachusetts Amherst.
 */

#pragma once
#ifndef MESH_STATIC__LOG_H
#define MESH_STATIC__LOG_H

#include "if.h"

int constexpr staticlog(int v) {
  return ((v == 1) ? 0 : (v == 2) ? 1 : (v > 1) ? staticlog(v / 2) + 1 : 0);
}

#else

template <int Number>
class StaticLog;

template <>
class StaticLog<1> {
public:
  enum { VALUE = 0 };
};

template <>
class StaticLog<2> {
public:
  enum { VALUE = 1 };
};

template <int Number>
class StaticLog {
public:
  enum { VALUE = StaticIf<(Number > 1), StaticLog<Number / 2>::VALUE + 1, 0>::VALUE };
};

#endif

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mesh-rb-0.0.1 ext/mesh/mesh/src/static/log.h