Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SFINAE usage in insert and do_intersect functions on Ubuntu 24.04 #8770

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ViNN280801
Copy link

Summary of Changes

I fixed an error in the code related to the incorrect use of std::is_same. In the source code, there was an attempt to use std::is_some<int, int>::type as a function parameter, which caused a compilation error. I removed this unnecessary parameter and added type checking using SFINAE (std::enable_if).
I have Ubuntu 24.04:

loveit0@loveit0-Nitro-AN515-58:~$ uname -a
Linux loveit0-Nitro-AN515-58 6.11.0-17-generic #17~24.04.2-Ubuntu SMP PREEMPT_DYNAMIC Mon Jan 20 22:48:29 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

I used the CGAL in my project for intersections with AABB and when I compiling my code, I faced with these kind of errors:

/usr/local/include/CGAL/Arrangement_2/Arrangement_on_surface_2_global.h:145:27: error: ‘std::is_same<__remove_cv(int), int>::type’ is not a type
  145 |             const PointLocation& pl, ZoneVisitor &visitor,
      |                           ^~~
/usr/local/include/CGAL/Arrangement_2/Arrangement_on_surface_2_global.h:471:27: error: ‘std::is_same<__remove_cv(int), int>::type’ is not a type
  471 |             InputIterator begin, InputIterator end,
      |                           ^~~
/usr/local/include/CGAL/Arrangement_2/Arrangement_on_surface_2_global.h:1534:5: error: ‘std::is_same<__remove_cv(int), int>::type’ is not a type
 1534 |              const PointLocation& pl, std::is_same<int, int>::type)
      |     ^  

Release Management

  • Affected package(s): Arrangement_on_surface_2
  • Issue(s) solved (if any): -
  • Feature/Small Feature (if any): N/A
  • License and copyright ownership: This contribution is licensed under the terms used by CGAL, and the authorship remains with the contributors.

@sloriot
Copy link
Member

sloriot commented Mar 5, 2025

Thanks for the PR! Do you have an example that we could compile and that is showing the error?

@ViNN280801
Copy link
Author

I don't know why, but it occurs in yours code when I am compiling my code
image

But when I making minimal example with do_intersect:

main.cpp

#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/intersections.h>

using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
using Point = Kernel::Point_3;
using Segment = Kernel::Segment_3;
using Triangle = Kernel::Triangle_3;

int main()
{
    Segment segment(Point(0, 0, 0), Point(1, 1, 1));
    Triangle triangel(Point(0, 0, 0), Point(1, 0, 0), Point(0, 1, 0));
    bool intersects = CGAL::do_intersect(segment, triangel);

    return 0;
}

main.cpp

cmake_minimum_required(VERSION 3.10)
project(example)

# GMP Setup
find_path(GMP_INCLUDE_DIR gmp.h HINTS /usr/include/x86_64-linux-gnu
                                      /usr/include/CGAL)
find_library(
  GMP_LIBRARY
  NAMES gmp libgmp
  HINTS /usr/lib/x86_64-linux-gnu)
if(NOT GMP_INCLUDE_DIR OR NOT GMP_LIBRARY)
  message(FATAL_ERROR "GMP not found. Please ensure GMP is installed.")
endif()
include_directories(${GMP_INCLUDE_DIR})
link_libraries(${GMP_LIBRARY})

# CGAL Setup
find_package(CGAL REQUIRED)

# Compile
add_executable(example main.cpp)

of course it compiles successfully:
image

If you need to get error like me, you can compile my repo Start or I can try to make minimal example, but I need time😬

@ViNN280801
Copy link
Author

and I really don't understand why I have errors in CGAL header file
/usr/local/include/CGAL/Arrangement_2/Arrangement_on_surface_2_global.h
it's really strange, and the one thing that helps me is add SFINAE using std::enable_if_t:

  1. Changing No 1
template <typename GeometryTraits_2, typename TopologyTraits,
         typename PointLocation, typename ZoneVisitor>
void insert(Arrangement_on_surface_2<GeometryTraits_2, TopologyTraits>& arr,
           const typename GeometryTraits_2::X_monotone_curve_2& c,
           const PointLocation& pl, ZoneVisitor &visitor,
           std::is_same<int, int>::type)

to

template <typename GeometryTraits_2, typename TopologyTraits,
          typename PointLocation, typename ZoneVisitor,
          typename = std::enable_if_t<std::is_same<PointLocation, int>::value>>
void insert(Arrangement_on_surface_2<GeometryTraits_2, TopologyTraits>& arr,
            const typename GeometryTraits_2::X_monotone_curve_2& c,
            const PointLocation& pl, ZoneVisitor &visitor)
  1. Changing No 2
template <typename GeometryTraits_2, typename TopologyTraits,
          typename InputIterator>
void insert(Arrangement_on_surface_2<GeometryTraits_2, TopologyTraits>& arr,
            InputIterator begin, InputIterator end,
            std::is_same<int, int>::type)

to

template <typename GeometryTraits_2, typename TopologyTraits,
          typename InputIterator,
          typename = std::enable_if_t<std::is_same<InputIterator, int>::value>>
void insert(Arrangement_on_surface_2<GeometryTraits_2, TopologyTraits>& arr,
            InputIterator begin, InputIterator end)
  1. Changing No 3
template <typename GeometryTraits_2, typename TopologyTraits,
          typename PointLocation>
bool
do_intersect(Arrangement_on_surface_2<GeometryTraits_2, TopologyTraits>& arr,
             const typename GeometryTraits_2::X_monotone_curve_2& c,
             const PointLocation& pl, std::is_same<int, int>::type)

to

template <typename GeometryTraits_2, typename TopologyTraits,
          typename PointLocation,
          typename = std::enable_if_t<std::is_same<PointLocation, int>::value>>
bool
do_intersect(Arrangement_on_surface_2<GeometryTraits_2, TopologyTraits>& arr,
             const typename GeometryTraits_2::X_monotone_curve_2& c,
             const PointLocation& pl)

And only after I changed this file, everything compiled successfully for me. Maybe my case is single or maybe I configured smth wrong, don't know exactly.

@ViNN280801
Copy link
Author

btw, tests are successfull

image

@efifogel
Copy link
Member

efifogel commented Mar 5, 2025 via email

@ViNN280801
Copy link
Author

my project uses CUDA, so, I used nvcc_wrapper from kokkos
but what about gcc/g++

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants