Loading [MathJax]/extensions/tex2jax.js
ug4
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
util.h
Go to the documentation of this file.
1
2#ifndef UG_BASE_LIB_ALGEBRA_ORDERING_STRATEGIES_ALGORITHMS_UTIL_H
3#define UG_BASE_LIB_ALGEBRA_ORDERING_STRATEGIES_ALGORITHMS_UTIL_H
4
5#include <boost/graph/adjacency_list.hpp>
6#include <boost/graph/graph_traits.hpp>
7#include "common/error.h" // UG_THROW
8
9namespace ug{
10
11#ifndef HAVE_BOOL
12#define HAVE_BOOL
13
14class BOOL{
15public:
16 BOOL() : value_(bool()){}
17 BOOL(bool const& t): value_(t) {}
18 operator bool() const { return value_; }
19private:
20 char value_;
21};
22
23#endif
24
25
26#ifndef HAVE_IS_PERMUTATION
27#define HAVE_IS_PERMUTATION
28
29template <typename O_t>
30bool is_permutation(O_t &o){
31 std::vector<BOOL> container(o.size(), false);
32 for(unsigned i = 0; i < o.size(); ++i){
33 if(!container[o[i]]){
34 container[o[i]] = true;
35 }
36 else{
37 UG_THROW("is_permutation: multiple occurence of index, i=" << i << ", o[i]=" << o[i] << "\n");
38 return false; //no doubles allowed
39 }
40 }
41
42 for(unsigned i = 0; i < o.size(); ++i){
43 if(!container[i]){
44 UG_THROW("is_permutation: no occurence of index " << i);
45 return false;
46 }
47 }
48
49 return true;
50}
51
52#endif
53
54}
55
56#endif
char value_
Definition permutation_util.h:126
BOOL(bool const &t)
Definition util.h:17
BOOL()
Definition util.h:16
#define UG_THROW(msg)
Definition error.h:57
the ug namespace
bool is_permutation(O_t &o)
Definition permutation_util.h:135