MantisBT
Mantis Bug Tracker Workflow

View Revisions: Issue #29299 All Revisions ] Back to Issue ]
Summary 0029299: Foundation Classes, NCollection - define explicit empty constructor for map classes
Revision 2017-11-07 18:41 by kgv
Description Currently NCollection_Map, NCollection_DataMap define the following constructors:
  NCollection_DataMap (const Standard_Integer NbBuckets=1,
                     const Handle(NCollection_BaseAllocator)& theAllocator = 0L)

so that empty constructor is combined with initialization constructor by passing default arguments.

This may lead to broken code, when constructor is called implicitly by converting unrelated value to Standard_Integer, which is the first argument of map class constructor. In the following example, NCollection_Map::Contains (const NCollection_Map&) is called instead of NCollection_Map::Contains (const Quantity_ColorRGBA& ) because enumeration value can be used to initialize NCollection_Map() implicitly (this is for msvc10, newer compilers might put error here due to ambiguity):
NCollection_Map<Quantity_ColorRGBA, Quantity_ColorRGBAHasher> aColors;
if (aColors.Contains (Quantity_NOC_LIGHTGOLDENROD2))
{
  std::cerr << " @@ KO\n";
}
else
{
  std::cerr << " @@ OK\n";
}


Therefore, it is proposed defining explicit empty constructor and marking current constructor with explicit keyword.
Revision 2017-11-07 17:08 by kgv
Description Currently NCollection_Map, NCollection_DataMap define the following constructors:
  NCollection_DataMap (const Standard_Integer NbBuckets=1,
                     const Handle(NCollection_BaseAllocator)& theAllocator = 0L)

so that empty constructor is combined with initialization constructor by passing default arguments.

This may lead to broken code, when constructor is called implicitly by converting unrelated value to Standard_Integer, which is the first argument of map class constructor. In the following example, NCollection_Map::Contains (const NCollection_Map&) is called instead of NCollection_Map::Contains (const Quantity_ColorRGBA& ) because enumeration value can be used to initialize NCollection_Map() implicitly (this is for msvc10, newer compilers might put error here due to ambiguity):
NCollection_Map<Quantity_ColorRGBA, Quantity_ColorRGBAHasher> aColors;
if (aColors.Contains (Quantity_NOC_LIGHTGOLDENROD2))
{
  std::cerr << " @@ KO\n";
}
else
{
  std::cerr << " @@ OO\n";
}


Therefore, it is proposed defining explicit empty constructor and marking current constructor with explicit keyword.


Copyright © 2000 - 2020 MantisBT Team
Powered by Mantis Bugtracker