std::set<Point<dim>> : missing operator(s)

23 views
Skip to first unread message

Simon

unread,
Jun 27, 2021, 6:15:40 AM6/27/21
to deal.II User Group
Dear all,

I am trying to create a set of Points<dim>, i.e std::set<Point<dim>>.
I get a quite extensive error message when trying to insert a point in the set but for my understanding of the message, the only problem is the missing operator< for two points.
(Well I could make use of a std::vector instead but a std::set fits much better for my issue since (i) I need to insert points at arbitrary positions quite often and second (ii) wanna make sure that a given Point is only once in the container.)

But irrespective of what container I use, I would like to supplement the Point Class by adding the 'operator<' like in the following:

template<int dim, typename Number=double>
bool Point<dim>::operator< (const Point<dim,Number>& p)
{
//...some Asserts
return this.norm()<p.norm();
}

Of course I can not write this piece of code since there is no declaration for a member function 'operator<' in the Point Class.
For that reasons my next idea was to modify the file <deal.II/base/point.h> by simply adding the missing operator< declaration and the corresponding definition. So I did this but without effect, probably because all the files of the dealii-library are already compiled and executing my program via 'make run' did not see my changes in the Point Class at all. (I also added a dummy command, std::cout<<"...Test..."<<std::endl, which did not appear on my screen either.)

I am only familiar with basic cmake- and make-commands.
My question is if it is possible to recompile one specific file of the library again?
So if this were possible I would appreciate getting some guidance for implementing this.
I would also be interested in writing a patch for that issue.

Best
Simon

Peter Munch

unread,
Jun 27, 2021, 6:25:04 AM6/27/21
to deal.II User Group
Hi Simon,

you don't need to modify the point class. You can simply pas to the constructor of the set a comparator. See the first answer in https://stackoverflow.com/questions/2620862/using-custom-stdset-comparator.

Hope this helps,
PM

Simon Wiesheier

unread,
Jun 27, 2021, 10:44:00 AM6/27/21
to dea...@googlegroups.com
Hi Peter,

Thanks a lot!

It worked for me like this (described in https://www.cplusplus.com/reference/set/set/set/ ):
bool(*fn_pt)(Point<dim>,Point<dim>) = comp_points; //comp_points is my function as I declared it in the question
std::set< Point<dim>, bool(*)(Point<dim>,Point<dim>) > vertices(fn_pt);

Just for a better understanding, the following approach from your linked website did not work:
std::set< Point<dim>, decltype(&comp_points) > vertices(&comp_points);

There are four errors:
-decltype cannot resolve address of overloaded function
-template argument 2 is invalid
-request for member ‘insert’ in ‘vertices’, which is of non-class type ‘int’
-cannot resolve overloaded function ‘comp_points’ based on conversion to type ‘int’

As far as I understood, decltype(&comp_points) returns ' bool(*)(Point<dim>,Point<dim> ' ,i.e it should be exactly the same as my first version, isn't it?

Best
Simon


--
The deal.II project is located at http://www.dealii.org/
For mailing list/forum options, see https://groups.google.com/d/forum/dealii?hl=en
---
You received this message because you are subscribed to the Google Groups "deal.II User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dealii+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dealii/34faa5ae-9bed-4a66-ad9f-cb2bb59d7ba1n%40googlegroups.com.

Wolfgang Bangerth

unread,
Jun 28, 2021, 9:02:31 PM6/28/21
to dea...@googlegroups.com
On 6/27/21 8:43 AM, Simon Wiesheier wrote:
>
> Just for a better understanding, the following approach from your linked
> website did not work:
> std::set< Point<dim>, decltype(&comp_points) > vertices(&comp_points);

If `comp_points` is a template, then you need to say
&comp_points<dim>

Best
W.

--
------------------------------------------------------------------------
Wolfgang Bangerth email: bang...@colostate.edu
www: http://www.math.colostate.edu/~bangerth/

Reply all
Reply to author
Forward
0 new messages