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);
232 template<
class ForwardIterator,
class T>
235 ForwardIterator it = std::lower_bound(first, last,
value);
236 return (it == last ||
value < *it) ? last : it;
242 template<
class ForwardIterator,
class T,
class Compare>
243 ForwardIterator
binary_find(ForwardIterator first, ForwardIterator last,
const T &
value, Compare comp)
245 ForwardIterator it = std::lower_bound(first, last,
value, comp);
246 return (it == last || comp(
value,*it)) ? last : it;
254 template <
int N,
typename T>
265 return xNover2*xNover2;
272 template <
typename T>
283 template <
typename T>
285 static inline T
apply (
const T & x) {
return x; }
288 template <
typename T>
290 static inline T
apply (
const T &) {
return 1; }
294 template <
int N,
typename T>
308 unsigned int factorial_n = 1;
313 for (
unsigned int i=1; i<n; i++)
321 template <
typename T>
331 for (T i = 0; i < k; ++i)
344 template <
typename T>
347 std::vector<T>().swap(vec);
354 std::string_view
basename_of(
const std::string & fullname);
360 bool contains(std::string_view superstring,
361 std::string_view substring);
367 bool ends_with(std::string_view superstring,
368 std::string_view suffix);
373 #ifdef LIBMESH_USE_COMPLEX_NUMBERS 381 unsigned int r_o_c=0);
387 std::vector<Real> & real_part,
388 std::vector<Real> & imag_part);
390 #endif // #ifdef LIBMESH_USE_COMPLEX_NUMBERS 396 int mkdir(
const char* pathname);
432 template <
typename T>
457 template <
typename T>
464 unsigned char *
b = (
unsigned char *) &data;
467 int j=(
sizeof(T) - 1);
471 std::swap (
b[i],
b[j]);
499 bool operator()(
const std::unique_ptr<T> & a,
const std::unique_ptr<T> &
b)
const 501 return a.get() <
b.get();
508 bool operator()(
const std::unique_ptr<T> & a,
const T *
const &
b)
const 517 bool operator()(
const T *
const & a,
const std::unique_ptr<T> &
b)
const 527 #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.
bool ends_with(std::string_view superstring, std::string_view suffix)
Look for a substring at the very end of a string.
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()
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)
bool contains(std::string_view superstring, std::string_view substring)
Look for a substring within a string.
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
std::string_view basename_of(const std::string &fullname)
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.
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.