473,888 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Long Generic Instantiations

I'm trying to do the equivalent of using typedefs with templates in C++ to
avoid long instantiation names.

I can do this okay:

using BigDictionary = System.Collecti ons.Generic.Dic tionary<int,
System.Collecti ons.Generic.Dic tionary<int, string>>;

class MyClass
{
private BigDictionary myDictionary;
}

But I think it would be tidier to break it down, something like:

using InnerDictionary = System.Collecti ons.Generic.Dic tionary<int, string>;
using BigDictionary =
System.Collecti ons.Generic.Dic tionary<int,Inn erDictionary>;

class MyClass
{
private BigDictionary myDictionary;
}

However, InnerDictionary is not recognised in the declaration of
BigDictionary. Is there any way I can do this?

In practice, the types I am using are fully scoped, rather than being
fundamental types, so the whole thing is even more verbose.

Thank is advance.
Nov 17 '05 #1
2 2038
Jasper,

Unfortunately, there is no way to do this. The using statement doesn't
allow references to other using statements, so you will have to create
separate aliases for each.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Jasper Kent" <ja*********@ho tmail.com> wrote in message
news:91******** **********@news fe3-gui.ntli.net...
I'm trying to do the equivalent of using typedefs with templates in C++ to
avoid long instantiation names.

I can do this okay:

using BigDictionary = System.Collecti ons.Generic.Dic tionary<int,
System.Collecti ons.Generic.Dic tionary<int, string>>;

class MyClass
{
private BigDictionary myDictionary;
}

But I think it would be tidier to break it down, something like:

using InnerDictionary = System.Collecti ons.Generic.Dic tionary<int,
string>;
using BigDictionary =
System.Collecti ons.Generic.Dic tionary<int,Inn erDictionary>;

class MyClass
{
private BigDictionary myDictionary;
}

However, InnerDictionary is not recognised in the declaration of
BigDictionary. Is there any way I can do this?

In practice, the types I am using are fully scoped, rather than being
fundamental types, so the whole thing is even more verbose.

Thank is advance.

Nov 17 '05 #2
Jasper,
Have you considered inheritance?

As the import alias is nothing more then an alias that is local to that
source file.

Something like (not tested):

class InnerDictionary : System.Collecti ons.Generic.Dic tionary<int,
string>
{ }

class BigDictionary :
System.Collecti ons.Generic.Dic tionary<int,Inn erDictionary>
{ }

Hope this helps
Jay
"Jasper Kent" <ja*********@ho tmail.com> wrote in message
news:91******** **********@news fe3-gui.ntli.net...
| I'm trying to do the equivalent of using typedefs with templates in C++ to
| avoid long instantiation names.
|
| I can do this okay:
|
| using BigDictionary = System.Collecti ons.Generic.Dic tionary<int,
| System.Collecti ons.Generic.Dic tionary<int, string>>;
|
| class MyClass
| {
| private BigDictionary myDictionary;
| }
|
| But I think it would be tidier to break it down, something like:
|
| using InnerDictionary = System.Collecti ons.Generic.Dic tionary<int,
string>;
| using BigDictionary =
| System.Collecti ons.Generic.Dic tionary<int,Inn erDictionary>;
|
| class MyClass
| {
| private BigDictionary myDictionary;
| }
|
| However, InnerDictionary is not recognised in the declaration of
| BigDictionary. Is there any way I can do this?
|
| In practice, the types I am using are fully scoped, rather than being
| fundamental types, so the whole thing is even more verbose.
|
| Thank is advance.
|
|
Nov 17 '05 #3

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

Similar topics

35
2359
by: Gabriel Zachmann | last post by:
Is there any generic way to use C++ libraries from within Python. I seem to recall that there are tools to generate wrappers for C-libraries semi-automatically. But those were still way too cumbersome, IMHO. What I would like to have is some module (or whatever), with which I can say "load this C++ library", and then, "create that C++ object" or "call method x of C++ object y".
7
1652
by: Master of C++ | last post by:
Hello Folks, I have a programming dilemma with templates and "genericity". I can think of a few solutions, but I am not sure which one is the best in terms of genetic C++ style. Any suggestions will be greatly appreciated. I am writing a template class Polynomial that encapsulates the functionalities of a Polynomial. Here is a rough sketch for the class:
4
2111
by: Cool Guy | last post by:
I don't understand the third paragraph under the heading 'Generic type instantiations' on <http://msdn.microsoft.com/vcsharp/2005/overview/language/generics/>: | The .NET Common Language Runtime creates a specialized copy of the | native code for each generic type instantiation with a value type, | but shares a single copy of the native code for all reference | types (since, at the native code level, references are just | pointers with...
2
2072
by: Bob Day | last post by:
Using VS 2003, Vb, MSDE... Option 1 ------------------------------------------- Thread A and B are instantiations of 2 different classes. If thread A raises an event caught by thread B, the delagate in thread B that executes is 1) running under thread A based on the debug threading window and 2) does not seem to be aware of any instantiations of thread B in its declarations section. See **** for what fails. Class B (which is thread...
3
2744
by: sks | last post by:
Hello all Is the usage of extern keyword valid for telling the compiler to NOT instantiate a template and to link it from an another binary? For example: Suppose module A's binary contains a template class called "myTemplate", for which there is an instantiation for 'int' type. Now suppose a class in module B binary wants to use this template
28
2652
by: steve yee | last post by:
i think c should adapt c++ template standard, as well as namespace. if so, c can replace c++ in many cases.
6
7669
by: Jorge Varas | last post by:
Hi all, Is it possible to have a collection of a generic type? for example: class a<twhere t : class, new { }
22
3546
by: amygdala | last post by:
Hi, I'm trying to grasp OOP to build an interface using class objects that lets me access database tables easily. You have probably seen this before, or maybe even built it yourself at some point in time. I have studied some examples I found on the internet, and am now trying to build my own from scratch. I have made a default table class (DB_Table), a default validation class (Validator) which is an object inside DB_Table and my...
2
1597
by: mde | last post by:
I'm wondering if there is a "best practice" for *creating doctests in methods* that reduces clutter/duplication of dummy instantiations. In the following code there are five (labeled 1-5) possible places to put a dummy mock instantiation. I have the impression that creating the dummies in every method is the common practice (1-3), but I'm hoping otherwise. I've found that creating the dummy down by the testmod call obviates the need...
0
9961
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9800
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11182
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10886
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7990
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7148
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5824
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6014
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4642
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.