 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Andreas Kabel Guest
|
Posted: Thu Apr 15, 2004 8:22 pm Post subject: Was setzt ::std::vector::insert voraus? |
|
|
Gegeben sei folgender Code:
///////////////
struct B {
};
struct A {
explicit A(const B&);
A& operator =(const B&);
};
int main() {
::std::vector<A> a;
::std::vector<B> b;
a.insert(a.end(), b.begin(), b.end());
}
///////////////
gcc 3.2 kompiliert anstandslos. Intel icc 8.0 meldet:
/opt/intel_cc_80/include/c++/memory(85): error: no suitable user-defined
conversion from "std::allocator<B>::value_type" to "const A" exists
, was durch a.insert in der letzten Zeile von main() getriggert wird.
Loeschen von "explicit" fuehrt zum Verschwinden der Fehlermeldung. Wer
hat recht -- Intel oder GNU? Nach Lektuere des Standards scheint mir,
als dass die Existenz eines Konstruktors reichen muss, und den gibt es
ja, aber die Stelle ist etwas unklar.
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
Albrecht Fritzsche Guest
|
Posted: Fri Apr 16, 2004 7:24 am Post subject: Re: Was setzt ::std::vector::insert voraus? |
|
|
Andreas Kabel wrote:
| Quote: | gcc 3.2 kompiliert anstandslos. Intel icc 8.0 meldet:
/opt/intel_cc_80/include/c++/memory(85): error: no suitable user-defined
conversion from "std::allocator<B>::value_type" to "const A" exists
, was durch a.insert in der letzten Zeile von main() getriggert wird.
Loeschen von "explicit" fuehrt zum Verschwinden der Fehlermeldung. Wer
hat recht -- Intel oder GNU? Nach Lektuere des Standards scheint mir,
als dass die Existenz eines Konstruktors reichen muss, und den gibt es
ja, aber die Stelle ist etwas unklar.
|
(ohne Standard-Nachschlagen) Intern wird da ja wohl sowas wie
(Pseudo-Code) hier stattfinden:
bPtr = b.begin()
aPtr = a.begin()
while (bPtr != b.end())
a.allocator.construct(aPtr, *bPtr)
++bPtr
++aPtr
Mit
template <typename T>
Allocator::construct(pointer p, const T& value);
Da ist also eine implizite Konvertierung noetig, die Du "dank" explicit
unterbindest. Daher hat Intel also recht. Vielleicht verwendet Dein gcc
irgendwelche Optimierungen an dieser Stelle
Ali
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
Albrecht Fritzsche Guest
|
Posted: Fri Apr 16, 2004 5:10 pm Post subject: Re: Was setzt ::std::vector::insert voraus? |
|
|
Andreas Kabel wrote:
| Quote: | gcc 3.2 kompiliert anstandslos. Intel icc 8.0 meldet:
|
Waehrend ich noch ueber Konzepte a lá Assignable etc nach-
gedacht hatte, habe ich mal Dein Bsp auf gcc 3.2.2 getestet.
Und - es kompilierte mit explicit nicht, jedoch ohne.
Hast Du vielleicht die Compiler verwechselt?
Ali
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
Andreas Kabel Guest
|
Posted: Fri Apr 16, 2004 6:00 pm Post subject: Re: Was setzt ::std::vector::insert voraus? |
|
|
Albrecht Fritzsche wrote:
| Quote: | Andreas Kabel wrote:
gcc 3.2 kompiliert anstandslos. Intel icc 8.0 meldet:
Waehrend ich noch ueber Konzepte a lá Assignable etc nach-
gedacht hatte, habe ich mal Dein Bsp auf gcc 3.2.2 getestet.
Und - es kompilierte mit explicit nicht, jedoch ohne.
Hast Du vielleicht die Compiler verwechselt?
|
Pardon. Ich hatte meuchlings upgedatet. gcc 3.3.3.
--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|