[ICL] Can't use an enum as map value
Hello,
I declared an interval_map :
interval_map
2014-03-19 13:11 GMT+01:00 Oodini
Hello,
I declared an interval_map :
interval_map
myMap; Later, I do :
SomeEnumType enumValue = SOME_ENUM_VALUE; myMap.add(std::make_pair(disxrete_interval
(10,17), SOME_ENUM_VALUE); But that doesn't compile.
It seems that ICL wants the += operator must eb defined for value type (why ???).
What can I do ?
Hi, If I remember correctly, you need to supply a combiner. The default combiner uses +=. A combiner produces a new value for overlapping intervals. Consider (pseudocode): myMap.add( [10,17), SOME_ENUM_VALUE ); myMap.add( [16,18), OTHER_ENUM_VALUE ); The combiner decides, what should be the value in [16,17). In this case, tries to += the OTHER_ENUM_VALUE to the existing SOME_ENUM_VALUE. HTH, Kris
Thanks for your prompt reply ! The problem is I DO KNOW there will be never overlapping. ----- Mail original -----
De: "Krzysztof Czainski" <1czajnik@gmail.com> À: boost-users@lists.boost.org Envoyé: Mercredi 19 Mars 2014 13:18:39 Objet: Re: [Boost-users] [ICL] Can't use an enum as map value
2014-03-19 13:11 GMT+01:00 Oodini < svdbg___@free.fr > :
Hello,
I declared an interval_map :
interval_map
myMap; Later, I do :
SomeEnumType enumValue = SOME_ENUM_VALUE; myMap.add(std::make_pair(disxrete_interval
(10,17), SOME_ENUM_VALUE); But that doesn't compile.
It seems that ICL wants the += operator must eb defined for value type (why ???).
What can I do ?
Hi,
If I remember correctly, you need to supply a combiner. The default combiner uses +=.
A combiner produces a new value for overlapping intervals. Consider (pseudocode):
myMap.add( [10,17), SOME_ENUM_VALUE ); myMap.add( [16,18), OTHER_ENUM_VALUE );
The combiner decides, what should be the value in [16,17). In this case, tries to += the OTHER_ENUM_VALUE to the existing SOME_ENUM_VALUE.
HTH, Kris _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
On Wed, Mar 19, 2014 at 01:41:03PM +0100, Oodini wrote:
Thanks for your prompt reply !
The problem is I DO KNOW there will be never overlapping.
That's run-time knowledge that the compiler can't infer or use. Investigate whether it's possible to avoid this behaviour via some policy or if it might be acceptable to have a bogus operator+= defined for your type somewhere where it can be found. If none of those are acceptable, you could always consider patching the library to provide such a policy or trait. -- Lars Viklund | zao@acc.umu.se
That's run-time knowledge that the compiler can't infer or use. Investigate whether it's possible to avoid this behaviour via some policy
Probably, but the documentation is not very clear about the policies.
or if it might be acceptable to have a bogus operator+= defined for your type somewhere where it can be found.
By using the insert() method, instead of add(), I can get what I wanted (see the other thred I initiated), because the insert() method isn't annoyed by the enum type.
If none of those are acceptable, you could always consider patching the library to provide such a policy or trait.
I'd like to, but I dont' think my employer will agree... (time is money !).
participants (3)
-
Krzysztof Czainski
-
Lars Viklund
-
Oodini