19 #ifndef LIBMESH_UTILITY_H 20 #define LIBMESH_UTILITY_H 23 #include "libmesh/libmesh_common.h" 39 #define libmesh_map_find(map, key) libMesh::Utility::map_find((map), (key), __FILE__, __LINE__) 46 #define libmesh_vector_at(vec, idx) libMesh::Utility::vector_at((vec), (idx), __FILE__, __LINE__) 68 static auto test(
const U* u) -> decltype(std::cout << *u);
70 static auto test(...) -> std::false_type;
85 #if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__) 87 #pragma GCC diagnostic push 88 #pragma GCC diagnostic ignored "-Wdangling-reference" 101 template<
typename Map,
typename Key,
104 typename Map::mapped_type &
107 const char * filename,
110 auto it = map.find(key);
111 libmesh_error_msg_if(it == map.end(),
112 "map_find() error: key not found in file " 113 << filename <<
" on line " << line_number);
120 template<
typename Map,
typename Key,
123 const typename Map::mapped_type &
126 const char * filename,
129 auto it = map.find(key);
130 libmesh_error_msg_if(it == map.end(),
131 "map_find() error: key not found in file " 132 << filename <<
" on line " << line_number);
140 template<
typename Map,
typename Key,
143 typename Map::mapped_type &
146 const char * filename,
149 auto it = map.find(key);
150 libmesh_error_msg_if(it == map.end(),
151 "map_find() error: key \"" << key <<
"\" not found in file " 152 << filename <<
" on line " << line_number);
159 template<
typename Map,
typename Key,
162 const typename Map::mapped_type &
165 const char * filename,
168 auto it = map.find(key);
169 libmesh_error_msg_if(it == map.end(),
170 "map_find() error: key \"" << key <<
"\" not found in file " 171 << filename <<
" on line " << line_number);
177 #if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__) 179 #pragma GCC diagnostic pop 189 template<
typename Vector>
191 typename Vector::reference &
193 typename Vector::size_type i,
194 const char * filename,
197 libmesh_error_msg_if(i >= vec.size(),
198 "vec_at() error: Index " << i <<
199 " past end of vector in file " << filename <<
200 " on line " << line_number);
207 template<
typename Vector>
209 typename Vector::const_reference &
211 typename Vector::size_type i,
212 const char * filename,
215 libmesh_error_msg_if(i >= vec.size(),
216 "vec_at() error: Index " << i <<
217 " past end of vector in file " << filename <<
218 " on line " << line_number);
223 #ifdef LIBMESH_ENABLE_DEPRECATED 228 template <
typename ForwardIter,
typename T>
229 void iota (ForwardIter first, ForwardIter last, T
value)
232 libmesh_deprecated();
234 while (first != last)
246 template<
class InputIterator >
249 libmesh_deprecated();
252 #endif // LIBMESH_ENABLE_DEPRECATED 264 template<
class ForwardIterator,
class T>
267 ForwardIterator it = std::lower_bound(first, last,
value);
268 return (it == last ||
value < *it) ? last : it;
274 template<
class ForwardIterator,
class T,
class Compare>
275 ForwardIterator
binary_find(ForwardIterator first, ForwardIterator last,
const T &
value, Compare comp)
277 ForwardIterator it = std::lower_bound(first, last,
value, comp);
278 return (it == last || comp(
value,*it)) ? last : it;
286 template <
int N,
typename T>
297 return xNover2*xNover2;
304 template <
typename T>
315 template <
typename T>
317 static inline T
apply (
const T & x) {
return x; }
320 template <
typename T>
322 static inline T
apply (
const T &) {
return 1; }
326 template <
int N,
typename T>
340 unsigned int factorial_n = 1;
345 for (
unsigned int i=1; i<n; i++)
353 template <
typename T>
363 for (T i = 0; i < k; ++i)
376 template <
typename T>
379 std::vector<T>().swap(vec);
385 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 393 unsigned int r_o_c=0);
399 std::vector<Real> & real_part,
400 std::vector<Real> & imag_part);
402 #endif // #ifdef LIBMESH_USE_COMPLEX_NUMBERS 408 int mkdir(
const char* pathname);
444 template <
typename T>
469 template <
typename T>
476 unsigned char * b = (
unsigned char *) &data;
479 int j=(
sizeof(T) - 1);
483 std::swap (b[i], b[j]);
511 bool operator()(
const std::unique_ptr<T> & a,
const std::unique_ptr<T> & b)
const 513 return a.get() < b.get();
520 bool operator()(
const std::unique_ptr<T> & a,
const T *
const & b)
const 529 bool operator()(
const T *
const & a,
const std::unique_ptr<T> & b)
const 540 #endif // LIBMESH_UTILITY_H std::string name(const ElemQuality q)
This function returns a string containing some name for q.
This Functor simply takes an object and reverses its byte representation.
const bool _do_reverse
flag
Map::mapped_type & map_find(Map &map, const Key &key, const char *filename, int line_number)
-Wdangling-reference was nowhere near ready to add to -Wall in gcc 13.
void deallocate(std::vector< T > &vec)
A convenient method to truly empty a vector using the "swap trick".
Vector::reference & vector_at(Vector &vec, typename Vector::size_type i, const char *filename, int line_number)
A replacement for std::vector::at(i) which is meant to be used with a macro, and, unlike at()...
void is_transparent
As of C++14, std::set::find() can be a templated overload.
int mkdir(const char *pathname)
Create a directory.
The libMesh namespace provides an interface to certain functionality in the library.
std::string system_info()
void iota(ForwardIter first, ForwardIter last, T value)
Utility::iota was created back when std::iota was just an SGI STL extension.
static T apply(const T &)
static T apply(const T &x)
T operator()(T &data) const
Functor.
std::string unzip_file(std::string_view name)
Create an unzipped copy of a bz2 or xz file, returning the name of the now-unzipped file that can be ...
bool operator()(const std::unique_ptr< T > &a, const std::unique_ptr< T > &b) const
This is already what the default operator< comparison for std::unique_ptrs does, we are not adding an...
void prepare_complex_data(const std::vector< Complex > &source, std::vector< Real > &real_part, std::vector< Real > &imag_part)
Prepare complex data for writing.
std::string complex_filename(std::string basename, unsigned int r_o_c=0)
An efficient template instantiation for raising to an arbitrary integer power.
static T apply(const T &x)
bool operator()(const T *const &a, const std::unique_ptr< T > &b) const
operator< comparison when lhs is a dumb pointer
static T apply(const T &x)
bool operator()(const std::unique_ptr< T > &a, const T *const &b) const
operator< comparison when rhs is a dumb pointer
Struct which defines a custom comparison object that can be used with std::sets of std::unique_ptrs...
unsigned int factorial(unsigned int n)
A simple implementation of the factorial.
bool is_sorted(InputIterator first, InputIterator last)
Utility::is_sorted was created back when std::is_sorted was just an SGI STL extension.
ForwardIterator binary_find(ForwardIterator first, ForwardIterator last, const T &value)
The STL provides std::binary_search() which returns true or false depending on whether the searched-f...
static auto test(const U *u) -> decltype(std::cout<< *u)
Helper struct for enabling template metaprogramming/SFINAE.
ReverseBytes(const bool dr)
Constructor.