You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
4.4 KiB

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.hpp :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: frdescam <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/04 16:27:14 by frdescam #+# #+# */
/* Updated: 2021/12/13 08:52:57 by frdescam ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef UTILS_HPP
# define UTILS_HPP
# include <cstddef>
namespace ft
{
template <class Iterator>
class iterator_traits
{
typedef typename Iterator::difference_type difference_type;
typedef typename Iterator::value_type value_type;
typedef typename Iterator::pointer pointer;
typedef typename Iterator::reference reference;
typedef typename Iterator::iterator_category iterator_category;
};
template <class T>
class iterator_traits<T *>
{
typedef ptrdiff_t difference_type;
typedef T value_type;
typedef T* pointer;
typedef T& reference;
typedef std::random_access_iterator_tag iterator_category;
};
template <class T>
class iterator_traits<const T *>
{
typedef ptrdiff_t difference_type;
typedef T value_type;
typedef const T *pointer;
typedef const T &reference;
typedef std::random_access_iterator_tag iterator_category;
};
template <class InputIterator1, class InputIterator2>
bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1,
InputIterator2 first2, InputIterator2 last2)
{
while (first1 != last1)
{
if (first2 == last2 || *first2 < *first1)
return false;
else if (*first1 < *first2)
return true;
++first1;
++first2;
}
return (first2 != last2);
};
template <class InputIterator1, class InputIterator2, class Compare>
bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2,
Compare comp)
{
while (first1 != last1)
{
if (first2 == last2 || comp(*first2, *first1))
return false;
else if (comp(*first1, *first2))
return true;
++first1;
++first2;
}
return (first2 != last2);
};
template <class InputIterator1, class InputIterator2>
bool equal(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2)
{
while (first1 != last1)
{
if (!(*first1 == *first2))
return false;
++first1;
++first2;
}
return true;
};
template <typename T>
struct is_pointer
{
static const bool value = false;
};
template <typename T>
struct is_pointer<T *>
{
static const bool value = true;
};
template <typename T>
struct is_void
{
static const bool value = false;
};
template <>
struct is_void<void>
{
static const bool value = true;
};
template <typename T>
struct is_integral
{
static const bool value = false;
};
template <>
struct is_integral<bool>
{
static const bool value = true;
};
template <>
struct is_integral<char>
{
static const bool value = true;
};
template <>
struct is_integral<unsigned char>
{
static const bool value = true;
};
template <>
struct is_integral<int>
{
static const bool value = true;
};
template <>
struct is_integral<unsigned int>
{
static const bool value = true;
};
template <>
struct is_integral<long>
{
static const bool value = true;
};
template <>
struct is_integral<long unsigned>
{
static const bool value = true;
};
template <>
struct is_integral<short>
{
static const bool value = true;
};
template <>
struct is_integral<short unsigned>
{
static const bool value = true;
};
template <>
struct is_integral<long long>
{
static const bool value = true;
};
template <>
struct is_integral<long long unsigned>
{
static const bool value = true;
};
template <bool Cond, class T = void>
struct enable_if
{
};
template <class T>
struct enable_if<true, T>
{
typedef T type;
};
};
#endif