473,327 Members | 1,952 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Koenig Lookup vs. Barton-Nackman Trick

I'm using a user-defined diagnostics stream and custom manipulators that work with it

template<class charT, class traits = std::char_traits<charT>
class basic_diagsstream : public std::basic_ostream<charT, traits

...
}

and a manipulator

class alar

template <typename charT, typename traits
friend basic_diagsstream<charT, traits>& operator <
(basic_diagsstream<charT, traits>& os, const alarm& a

// manipulate the diagnostics strea
..
return os

}

Intentionally, I defined the put operator inside the alarm manipulator, paying tribute to Angelika and Klaus for the boilerplate code, and to Nicolai and David for the Barton-Nackman explanation :-

I had been using code like this

// Works in VC
diags << "Hello, world"
diags << alarm(STOP_THE_WORLD_I_WANT_TO_GET_OFF)
diags << "Stop!" << alarm(I_WANT_TO_GET_OFF_TOO)

where diags is an instance of basic_diagstream

However, when porting to VC7.1, this code breaks. To fix it, I had to

- Bring the friend function definition for the put operator outside of the alarm manipulator
- Change the signature to take a basic_ostream instead
- Cast inside the global put operator

class alar

template <typename charT, typename traits
friend std::basic_osstream<charT, traits>& operator <
(std::basic_osstream<charT, traits>& os, const alarm& a)
}

template <typename charT, typename traits
std::basic_osstream<charT, traits>& operator <
(std::basic_osstream<charT, traits>& os, const alarm& a

// cast then manipulate..
dynamic_cast<basic_diagstream<charT, traits>>(os)
..
return os
Since VC7.1 is more compliant than VC7, I have the following questions (from the perspective of using VC7.1)

In VC7.1, when defining the put operator within the manipulator (alarm), the code does not compile. The compiler barfs that there is no suitable operator taking an alarm in the rhs. My assumption is that it had to do with Koenig Lookup finding the operator<< that takes an ostream, but could not find an overload that takes an alarm manipulator on its rhs. I would have expected it to find the operator defined inside the alarm manipulator, but it didn't, obviously

- Why does it work in VC7 and not in VC7.1? Does the friend name injection limit the name exposure of the operator<< inside the alarm manipulator (and this limitation is obviously applicable to VC7.1 only)

Regards

Javier Estrad

Nov 17 '05 #1
5 2327
Javier Estrada wrote:
- Why does it work in VC7 and not in VC7.1? Does the friend name
injection limit the name exposure of the operator<< inside the alarm
manipulator (and this limitation is obviously applicable to VC7.1
only)?


I see Daveed Vandevoorde responded to your posting of this issue in
comp.lang.c++.moderated. If you would be willing to put together a minimal
complete example that compiles under VC7 but fails under VC71 (and yet you
believe should compile) and post it here, I can test it with the whidbey
alpha compiler & submit a bug report for it if it's still broken in that
version.

-cd
Nov 17 '05 #2
Carl Daniel [VC++ MVP] <cp*****************************@mvps.org.nospam > wrote:
[...] If you would be willing to put together a minimal
complete example that compiles under VC7 but fails under VC71 (and yet you
believe should compile) and post it here, I can test it with the whidbey
alpha compiler & submit a bug report for it if it's still broken in that
version.
Carl,

I have seen statements like this numerous
times here during the last weeks. I assume
that, since reporting bugs for VC7.1 seems
to be considered wasting time, that there
is no intention to fix such bugs in SPs?
-cd


Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers dot org

"Sometimes compilers are so much more reasonable than people."
Scott Meyers
Nov 17 '05 #3
Hendrik Schober wrote:
Carl Daniel [VC++ MVP]
<cp*****************************@mvps.org.nospam > wrote:
[...] If you would be willing to put together a minimal
complete example that compiles under VC7 but fails under VC71 (and
yet you believe should compile) and post it here, I can test it with
the whidbey alpha compiler & submit a bug report for it if it's
still broken in that version.


Carl,

I have seen statements like this numerous
times here during the last weeks. I assume
that, since reporting bugs for VC7.1 seems
to be considered wasting time, that there
is no intention to fix such bugs in SPs?


I couldn't say whether there's any intention to make an SP for VC7.1. In
any case, SP's are by definition collections of QFEs. QFEs come into
existence through product support. So, if there's something that needs to
be fixed in VC7.1 in order for you to use the product effectively, you need
to report it to PSS and make them aware of how much it's impacting your day
to day work.

In other words, I post bugs to the Whidbey alpha because I can - not because
it's the only path into the system.

-cd
Nov 17 '05 #4
Carl Daniel [VC++ MVP] <cp*****************************@mvps.org.nospam > wrote:
[...]
In other words, I post bugs to the Whidbey alpha because I can - not because
it's the only path into the system.
I see. Thanks for the clarification.
-cd


Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers dot org

"Sometimes compilers are so much more reasonable than people."
Scott Meyers
Nov 17 '05 #5
As general guidance, issues in an area obscure enough to have Daveed make
the final call on what the standard really says are unlikely to get into an
SP. The bulk of the fixes we make go into the next product. Customer
critical issues (mainly rolled up QFEs) go into service packs.

As Carl said, if you call MS Developer Support and you can make the case
that any issue is absolutely critical for your use of the product, they will
submit a QFE request for it. And we do honor these QFE requests in over 95%
of the cases.

Ronald Laeremans
Visual C++ team

"Hendrik Schober" <Sp******@gmx.de> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Carl Daniel [VC++ MVP] <cp*****************************@mvps.org.nospam >

wrote:
[...]
In other words, I post bugs to the Whidbey alpha because I can - not because it's the only path into the system.


I see. Thanks for the clarification.
-cd


Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers dot org

"Sometimes compilers are so much more reasonable than people."
Scott Meyers

Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dave | last post by:
#include <iostream> using std::cout; using std::endl; // #define CAUSE_ERROR namespace N { struct foo_t {};
11
by: REH | last post by:
I'm a little confused about argument dependent lookup. Exactly when does this apply? Specifically, I was hoping to use it to access enumeration constants. For example: namespace Flags { enum...
8
by: Lucas Lemmens | last post by:
Dear pythonians, I've been reading/thinking about the famous function call speedup trick where you use a function in the local context to represent a "remoter" function to speed up the 'function...
2
by: Jean-Louis Leroy | last post by:
I'm trying to compile the following code with gcc (version below). I would expect the compile to try the operator ==() declared in Tangram::Backend because of Koenig lookup. But it doesn't happen....
3
by: my-wings | last post by:
I've been reading about how evil Lookup fields in tables are, but I've got to be missing something really basic. I know this subject has been covered before, because I've just spent an hour or two...
3
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems...
3
by: REH | last post by:
I'm a little confused about argument dependent lookup. Exactly when does this apply? Specifically, I was hoping to use it to access enumeration constants. For example: namespace Flags { enum...
2
by: cgv | last post by:
Hi, I want to distinguish between an int parameter to a template function depending on whether its value is known at compile time or not. For the compile time version I want to call the function...
16
by: Juha Nieminen | last post by:
The so-called koenig lookup allows doing odd things like this: #include <algorithm> #include <string> int main() { std::string table; sort(table, table+10); }
2
by: Peng Yu | last post by:
Hi, I'm wondering if Koenig lookup can be applied somehow to derive which template to use based on the template arguments. The following code shows an example where multiply_traits's namespace...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.