473,657 Members | 2,530 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Refactoring Traits and Policies (in Containers)

I see the STL using class templates accepting a traits and a policy.
To me, the traits are the "what" and the policy is the "how". How can
a policy know what to do without the traits of the topic? Wouldn't it
be better for containers to take a policy template argument and for
the policy to take a traits template argument? Consider an allocator
(policy) that is going to be used in a multi-threaded environment.
The programmer could use something like the following (simplified)
traits.

template<typena me TYPE>
struct NormalTraits
{
typedef TYPE value_type;
typedef value_type *pointer;
typedef std::size_t size_type;
};
template<>
struct NormalTraits<vo id>
{
private: typedef void TYPE;
typedef TYPE value_type;
typedef value_type *pointer;
typedef std::size_t size_type;
};

template<typena me TYPE>
struct VolatileTraits
{
typedef TYPE value_type;
typedef volatile value_type *pointer;
typedef std::size_t size_type;
};
template<>
struct VolatileTraits< void>
{
private: typedef void TYPE;
typedef TYPE value_type;
typedef volatile value_type *pointer;
typedef std::size_t size_type;
};

Now, a programmer could specify the VolatileTraits< to an allocator
policy for a multi-threaded container and the policy would know what
types should be given to the signatures of methods like 'pointer
allocate( size_type, typename
TRAITS::rebind< void>::other::c onst_pointer )'. How are traits
reflected in policies if they are only introduced to the container?
When would my refactoring not work?

Milburn Young

Jul 18 '07 #1
0 1080

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

Similar topics

1
1690
by: Donald 'Paddy' McCarthy | last post by:
Hi, I am having a few problems with a GUI. I am new to traits and wxGlade. I have used wxGlade to create a Form with an embedded space for a CustomWidget. I have the traits demo and would like to edit the traits and have the traits form appear instead of the space left for my CustomWidget. wxGlade produces code with the following hook (last line):
0
3744
by: skscpp | last post by:
What's wrong with the following code? Compiler error is at the bottom. The compiler I am using is gcc version 2.95. ============================= // traits.h ============================= #include <vector> #include <list> #include <set> #include <functional>
12
2426
by: Mark A. Gibbs | last post by:
Good day, What is the safest way to get a non-end of file value? char_traits<char_type>::eof() will get me eof, but how can I safely and consistently generate a value that is not eof? should i use ~char_traits<char_type>::eof()? char_traits<char_type>::int_type()? char_traits<char_type>::eof() + 1? while(!char_traits<char_type>::not_eof(char_traits<char_type>::int_type(rand())))? mark
8
1892
by: Jon Slaughter | last post by:
I'm reading Alexandrescu's Modern C++ design about the concept of policies. What I'm wondering is if policies are a common design pattern in C++(OOP) nowdays? It seems like a good idea but I'm having a little trouble following along and I'm wondering if I should put in the time to really understand it or if its just a waste because there are better things out there. Like all these things about traits, generics, policies, etc don't mean...
4
1399
by: loulou384 | last post by:
Refactoring by C. Keith Ray Software development on your project has slowed to a crawl. Instead of adding new features, you and your fellow programmers want to rewrite the existing code to make it easy to work with again, which of course frightens product marketing and your boss. How do we get into these messes? What can we do about it? Many books and courses teach principles, rules, and guidelines of good
19
3392
by: AlesD | last post by:
Hello, I have problem that when I use std::list<MyClassand then store various subclasses of MyClass in that list (or any other STL container) the instances get sliced. I have read FAQ: ' What is a "virtual constructor"?', but I miss information if there is some "workaround" when using STL containers, since I can't change them to call clone() instead of copy constructor.
5
1993
by: Diego Martins | last post by:
Hi all. I want to build a template class to extract the return type of a pointer to function Something like: template<typename CB> class ReturnTypeExtractor { typedef ReturnType .... ??? :-(
2
1720
by: Milburn Young | last post by:
I see the STL using class templates accepting a traits and a policy. To me, the traits are the "what" and the policy is the "how". How can a policy know what to do without the traits of the topic? Wouldn't it be better for containers to take a policy template argument and for the policy to take a traits template argument? Consider an allocator (policy) that is going to be used in a multi-threaded environment. The programmer could use...
2
3403
by: Colin J. Williams | last post by:
Using >easy_install -v -f http://code.enthought.com/enstaller/eggs/source enthought.traits The result is: .... many lines ....
0
8421
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
8844
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...
0
8742
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8518
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,...
0
8621
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5643
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
4173
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...
1
2743
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.