473,383 Members | 1,868 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,383 software developers and data experts.

static or not?

Whats the best way to implement this:

BBox BBox::Union(const BBox &b) const{
BBox u;
u.p_min.x = min(p_min.x, b.p_min.x); u.p_min.y = min(p_min.y,
b.p_min.y); u.p_min.z = min(p_min.z, b.p_min.z);
u.p_max.x = max(p_max.x, b.p_max.x); u.p_max.y = max(p_max.y,
b.p_max.y); u.p_max.z = max(p_max.z, b.p_max.z);
return u;
}

or static with two arguments. I'm thinking of making this inline ...
but I don't know why anyone supporting this?
Jan 28 '08 #1
3 1323
ooo, great suggestion:
return BBox(min( p_min, other.p_min ), max( p_max, other.p_max ));

I didn't know min and max worked for other types than the primitives.
Jan 28 '08 #2
On Jan 28, 2:12*pm, "Alf P. Steinbach" <al...@start.nowrote:
Whether to use the names "min" and "max" is another matter, which I
think can only be resolved by thinking about what makes sense (or not)
in your problem domain, and whether you plan on using or suspect you
might in future be using std::max or std::min for Point3D.
FWIW I don't see min and max being useful for points and vectors.

The only possible use is if you treat a vector as a sequence and then
do min or max on each element:

#include <vector>
#include <algorithm>
#include <iostream>

int main()
{
typedef std::vector<doublevect;

vect v1, v2, r_min(3), r_max(3);
v1.push_back(1);
v1.push_back(2);
v1.push_back(3);

v2.push_back(0.5);
v2.push_back(3);
v2.push_back(-1);

typedef double const &(*pf)(double const &, double const &);
std::transform(v1.begin(), v1.end(),
v2.begin(),r_min.begin(),pf(std::min));

for ( std::size_t i = 0; i < r_min.size(); ++i){
std::cout << r_min[i] <<'\n';
}
std::cout << "......\n";
std::transform(v1.begin(), v1.end(),
v2.begin(),r_max.begin(),pf(std::max));

for ( std::size_t i = 0; i < r_max.size(); ++i){
std::cout << r_max[i] <<'\n';
}

}

You can of course also write a version that acts on a tuple.

Alternatively xmin(Pt,Pt), ymin(Pt,Pt),zmin(Pt,Pt) are useful
returning the minimum x and y of the 2 points. In this case its
similar to writing out each iteration of the sequence.

OTOH funnily enough min and max could make sense for a bounding
box :-)

regards
Andy Little
Jan 28 '08 #3
On Jan 29, 12:14*pm, "Alf P. Steinbach" <al...@start.nowrote:
* kwikius:
Could add that its an unnecessary requirement AFAICS. (Perhaps the
return type was changed from value to const reference at some point.)
#include <algorithm>
#include <iostream>
struct my{
explicit *my (double v_in) : v (v_in){};
* double v;
private :
* *my ( my const &);
};
inline bool operator <
(my const & lhs, my const & rhs)
{
* *return lhs.v *< rhs.v;
}
int main()
{
* my x(1),y(2);
* my const & r = std::min(x,y);

Consider instead

* *my const& r = std::min( x, my(2) );
Ouch!. But Isnt whether 'my' is copy constructible or not irrelevant
here. It will still screw up just the same ?

hmmm....

<...>
I wonder if the code above will be valid in C++0x, and if so, how the
heck the compiler could implement the necessary lifetime extension for
the temporary?
hmm.... Mental note!

I'll look at the move constructible widget when it materialises,
meanwhile my overloads of min/max will return by value.

:-)

regards
Andy Little


Jan 29 '08 #4

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

Similar topics

8
by: Scott J. McCaughrin | last post by:
The following program compiles fine but elicits this message from the linker: "undefined reference to VarArray::funct" and thus fails. It seems to behave as if the static data-member:...
15
by: Samee Zahur | last post by:
Question: How do friend functions and static member functions differ in terms of functionality? I mean, neither necessarily needs an object of the class to be created before they are called and...
5
by: Mountain Bikn' Guy | last post by:
How would I do this? public sealed class UtilityClass { public static MyObject Object1;//see note below about importance of static object names in this class public static MyObject Object2;...
3
by: Jay | last post by:
Why are there static methods in C#. In C++ static was applied to data only (I believe) and it meant that the static piece of data was not a part of the object but only a part of the class (one...
9
by: Laban | last post by:
Hi, I find myself using static methods more than I probably should, so I am looking for some advice on a better approach. For example, I am writing an app that involves quite a bit of database...
12
by: Joe Narissi | last post by:
I know how to create and use static constructors, but is there a such thing as a static destructor? If not, then how do you deallocate memory intialized in the static constructor? Thanks in...
55
by: Zytan | last post by:
I see that static is more restricted in C# than in C++. It appears usable only on classes and methods, and data members, but cannot be created within a method itself. Surely this is possible in...
1
by: Sandro Bosio | last post by:
Hello everybody, my first message on this forum. I tried to solve my issue by reading other similar posts, but I didn't succeed. And forgive me if this mail is so long. I'm trying to achieve the...
9
by: Steve Richter | last post by:
in a generic class, can I code the class so that I can call a static method of the generic class T? In the ConvertFrom method of the generic TypeConvert class I want to write, I have a call to...
14
by: Jess | last post by:
Hello, I learned that there are five kinds of static objects, namely 1. global objects 2. object defined in namespace scope 3. object declared static instead classes 4. objects declared...
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: 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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.