<commit_before>/*
 *  Copyright 2008-2018 NVIDIA Corporation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

#include <thrust/detail/config.h>
#include <thrust/detail/allocator/allocator_traits.h>
#include <thrust/detail/type_traits/is_call_possible.h>
#include <thrust/detail/integer_traits.h>

#if THRUST_CPP_DIALECT >= 2011
  #include <thrust/detail/type_deduction.h>
#endif

#include <new>

namespace thrust
{
namespace detail
{
namespace allocator_traits_detail
{

__THRUST_DEFINE_IS_CALL_POSSIBLE(has_member_allocate_with_hint_impl, allocate)

template<typename Alloc>
  class has_member_allocate_with_hint
{
  typedef typename allocator_traits<Alloc>::pointer            pointer;
  typedef typename allocator_traits<Alloc>::size_type          size_type;
  typedef typename allocator_traits<Alloc>::const_void_pointer const_void_pointer;

  public:
    typedef typename has_member_allocate_with_hint_impl<Alloc, pointer(size_type,const_void_pointer)>::type type;
    static const bool value = type::value;
};

template<typename Alloc>
__host__ __device__
  typename enable_if<
    has_member_allocate_with_hint<Alloc>::value,
    typename allocator_traits<Alloc>::pointer
  >::type
    allocate(Alloc &a, typename allocator_traits<Alloc>::size_type n, typename allocator_traits<Alloc>::const_void_pointer hint)<commit_msg>Handle deprecated C++17 std::allocator API.<commit_after>/*
 *  Copyright 2008-2018 NVIDIA Corporation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

#include <thrust/detail/config.h>
#include <thrust/detail/allocator/allocator_traits.h>
#include <thrust/detail/type_traits/is_call_possible.h>
#include <thrust/detail/integer_traits.h>

#if THRUST_CPP_DIALECT >= 2011
  #include <thrust/detail/type_deduction.h>
#endif

#include <memory>
#include <new>

namespace thrust
{
namespace detail
{

#if THRUST_CPP_DIALECT >= 2011

// std::allocator's member functions are deprecated in C++17 and removed in
// C++20, so we can't just use the generic implementation for allocator_traits
// that calls the allocator's member functions.
// Instead, specialize allocator_traits for std::allocator and defer to
// std::allocator_traits<std::allocator> and let the STL do whatever it needs
// to for the current c++ version. Manually forward the calls to suppress
// host/device warnings.
template <typename T>
struct allocator_traits<std::allocator<T>>
  : public std::allocator_traits<std::allocator<T>>
{
private:
  using superclass = std::allocator_traits<std::allocator<T>>;

public:
  using allocator_type = typename superclass::allocator_type;
  using value_type = typename superclass::value_type;
  using pointer = typename superclass::pointer;
  using const_pointer = typename superclass::const_pointer;
  using void_pointer = typename superclass::void_pointer;
  using const_void_pointer = typename superclass::const_void_pointer;
  using difference_type = typename superclass::difference_type;
  using size_type = typename superclass::size_type;
  using propagate_on_container_swap = typename superclass::propagate_on_container_swap;
  using propagate_on_container_copy_assignment =
    typename superclass::propagate_on_container_copy_assignment;
  using propagate_on_container_move_assignment =
    typename superclass::propagate_on_container_move_assignment;

  // std::allocator_traits added this in C++17, but thrust::allocator_traits defines
  // it unconditionally.
  using is_always_equal = typename eval_if<
      allocator_traits_detail::has_is_always_equal<allocator_type>::value,
      allocator_traits_detail::nested_is_always_equal<allocator_type>,
      is_empty<allocator_type>
    >::type;

  template <typename U>
  using rebind_alloc = std::allocator<U>;
  template <typename U>
  using rebind_traits = allocator_traits<std::allocator<U>>;

  __thrust_exec_check_disable__
  __host__ __device__
  static pointer allocate(allocator_type &a, size_type n)
  {
    return superclass::allocate(a, n);
  }

  __thrust_exec_check_disable__
  __host__ __device__
  static pointer allocate(allocator_type &a, size_type n, const_void_pointer hint)
  {
    return superclass::allocate(a, n, hint);
  }

  __thrust_exec_check_disable__
  __host__ __device__
  static void deallocate(allocator_type &a, pointer p, size_type n)
  {
    superclass::deallocate(a, p, n);
  }

  __thrust_exec_check_disable__
  template <typename U, typename ...Args>
  __host__ __device__
  static void construct(allocator_type &a, U *p, Args&&... args)
  {
    superclass::construct(a, p, THRUST_FWD(args)...);
  }

  __thrust_exec_check_disable__
  template <typename U>
  __host__ __device__
  static void destroy(allocator_type &a, U *p)
  {
    superclass::destroy(a, p);
  }

  __thrust_exec_check_disable__
  __host__ __device__
  static size_type max_size(const allocator_type &a)
  {
    return superclass::max_size(a);
  }
};

#endif //  C++11

namespace allocator_traits_detail
{

__THRUST_DEFINE_IS_CALL_POSSIBLE(has_member_allocate_with_hint_impl, allocate)

template<typename Alloc>
  class has_member_allocate_with_hint
{
  typedef typename allocator_traits<Alloc>::pointer            pointer;
  typedef typename allocator_traits<Alloc>::size_type          size_type;
  typedef typename allocator_traits<Alloc>::const_void_pointer const_void_pointer;

  public:
    typedef typename has_member_allocate_with_hint_impl<Alloc, pointer(size_type,const_void_pointer)>::type type;
    static const bool value = type::value;
};

template<typename Alloc>
__host__ __device__
  typename enable_if<
    has_member_allocate_with_hint<Alloc>::value,
    typename allocator_traits<Alloc>::pointer
  >::type
    allocate(Alloc &a, typename allocator_traits<Alloc>::size_type n, typename allocator_traits<Alloc>::const_void_pointer hint)
{'fraction_non_alphanumeric': 0.08544117647058823, 'fraction_numerical': 0.006764705882352941, 'mean_word_length': 5.2972222222222225, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2264169', 'n_tokens_mistral': 2195, 'n_tokens_neox': 2063, 'n_words': 542}