![]() |
| | #106 | ||
| Banned Join Date: Nov 2007
Posts: 678
| Quote:
Quote:
)And what help it has over the plain and simple for() loop? All the rest you said was more like a learning to me, so I agree! | ||
| manav is offline | |
| | #107 | ||
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 11,263
| Quote:
Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | ||
| laserlight is offline | |
| | #108 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,767
| If you don't mind me asking, I was going to ask: The function Find is const because it does not change the class data, but it returns a non-const iterator, allowing the data later to be changed. Am I to interpret that Find should not be const or should I circumvent this? I get issues either way. If it's const, then, I cannot do: Code: if (uint32_t(pEnd - pStart) < nFindLength) return end(); //iterator(this, m_pUnusedStart); Code: nIndex = strToSplit.Find(strSplitWhat, nLastIndex); Code: const Strings::CStringEx& strToSplit Any ideas?
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #109 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 11,263
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is offline | |
| | #110 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,767
| Hmmm. Does that mean that an "internal" replace must return an integer or perhaps a pointer to the buffer instead of an iterator, then...? Seeing as I cannot call a non-const function from a const function and I cannot assign a const iterator to a non-const iterator. One more thing, though. If the function was to be separated (ie free), then how would you go about it, since it needs an "internal" function that should not be called directly. Code: template<typename StrType> void Replace(const StrType& strSrc, const StrType& strReplaceWhat, const StrType& strReplaceWith); //template<typename StrType, typename ItType> void Replace(const StrType& strReplaceWhat, const StrType& strReplaceWith, const ItType& vStart); template<typename StrType, typename ItType> void Replace(const StrType& strSrc, const StrType& strReplaceWhat, const StrType& strReplaceWith, const ItType& vStart, const ItType& vEnd); // NOT TO BE CALLED DIRECTLY template<typename StrType, typename ItType> int32_t ReplaceInternal(const StrType& strSrc, const StrType& strReplaceWhat, const StrType& strReplaceWith, bool bReplace, const ItType& vStart, const ItType& vEnd);
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
| | #111 |
| Banned Join Date: Nov 2007
Posts: 678
| Enough Hijacking!!! The people here are 'Concrete Minded'! Like me! ![]() Over to your real problem now! Have you thought, why you are having so many problems? You are constantly being bitten by how-to-do-it-in-C++! Later on poor users of your class may be wondering how-to-use-it-in-my-program? I guess, either you do not know enough C++ to do this, OR, C++ is so much of a Language, that no body, except Him, knows it well! *_* |
| manav is offline | |
| | #112 | |
| Afraid of widths Join Date: Apr 2008 Location: Chicago
Posts: 887
| Quote:
| |
| medievalelks is offline | |
| | #113 | ||
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,767
| Quote:
For example: Code: void foo(std::string& mystr) { }
void foo2(const std::string& mystr) { }
int main()
{
foo("test"); // Won't work
foo2("test"); // Will work
}
Don't be silly. Of course I know ways around it, but I was asking for advice. Screw that religion. It annoys me.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| ||
| Elysia is offline | |
| | #114 | |||
| Banned Join Date: Nov 2007
Posts: 678
| Quote:
![]() I was just a little concerned! Guess what, I know you know C++, hundred times more than I know! And I never had to use whatever you are using, even when it is almost a year, since I am working on this C++ project! Quote:
Quote:
| |||
| manav is offline | |
| | #115 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 11,263
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is offline | |
| | #116 | |||||
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,767
| Quote:
We'll see how easy you think it is to use! Quote:
You will face these problems too, eventually. And you will struggle. But eventually you will learn. Quote:
Quote:
The "internal" replace as you see requires more arguments (especially the bool) then the "normal" Replace. The "normal" replace comes in two variants and is supposed to be the public interface. It will do whatever is necessary and call the "internal" function. With classes, I could hide the internal function, but if Replace is free, then I can't hide that internal function. It shouldn't be called directly, so I was wondering the best way of doing it? Should I just let it lie there or put it in a private header or so?
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |||||
| Elysia is offline | |
| | #117 | ||
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 11,263
| Quote:
![]() Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | ||
| laserlight is offline | |
| | #118 | |||
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,767
| Quote:
Find had the const or not const iterator problem. Replace was broken out and have the private interface problem. Quote:
Code: template<typename StrType> void Replace(const StrType& strSrc,
const StrType& strReplaceWhat, const StrType& strReplaceWith)
{
Replace(strSrc, strReplaceWhat, strReplaceWith,
strReplaceWhat.begin(), strReplaceWhat.end());
}
//template<typename StrType, typename ItType> void Replace(const
StrType& strReplaceWhat, const StrType& strReplaceWith, const ItType& vStart);
template<typename StrType, typename ItType> void Replace(const StrType& strSrc,
const StrType& strReplaceWhat, const StrType& strReplaceWith, const ItType& vStart,
const ItType& vEnd)
{
int32_t nNeededSize = ReplaceInternal(strSrc, strReplaceWhat, strReplaceWith, false,
vStart, vEnd);
if (nNeededSize > 0) strSrc.resize(nNeededSize); //PrepareBuffer(nNeededSize);
ReplaceInternal(strSrc, strReplaceWhat, strReplaceWith, true, vStart, vEnd);
}
template<typename StrType, typename ItType> int32_t ReplaceInternal(const StrType& strSrc,
const StrType& strReplaceWhat, const StrType& strReplaceWith, bool bReplace,
const ItType& vStart, const ItType& vEnd) Then they will wrap ReplaceInternal that will do the actual replacing. But ReplaceInternal shouldn't be called directly because 1) it takes a bool that should not be passed directly and 2) it has only one version - the one that takes a range. Therefore ReplaceInternal should be hidden away from prying eyes, but since it's free it cannot. But making it a member will destroy the essence of generic functions... Unless ReplaceInternal can wrap other generic functions to do its work. Perhaps that might be a good idea? Then ReplaceInternal could be made a member.
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
Last edited by Elysia; 05-13-2008 at 05:40 AM. | |||
| Elysia is offline | |
| | #119 |
| Banned Join Date: Nov 2007
Posts: 678
| Thinking along the lines ... Code: Replace(DestSeq, startDest, endDest, SrcSeq, startSrc, endSrc) ... // Do not mind the mildly exaggerated tone of my post, but isn't that a possible solution? |
| manav is offline | |
| | #120 | |
| Mysterious C++ User Join Date: Oct 2007
Posts: 14,767
| No, it's not the interface per se that's the problem, but the internal mechanisms. And it should be Replace(What, With, Start, End).
__________________ Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System I dedicated my life to helping others. This is only a small sample of what they said: "Thanks Elysia. You're a programming master! How the hell do you know every thing?" Quoted... at least once. Quote:
| |
| Elysia is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| WS_POPUP, continuation of old problem | blurrymadness | Windows Programming | 1 | 04-20-2007 06:54 PM |
| Laptop Problem | Boomba | Tech Board | 1 | 03-07-2006 06:24 PM |
| implementation file | bejiz | C++ Programming | 5 | 11-28-2005 01:59 AM |
| Sorting problem.. well actually more of a string problem | fatdunky | C Programming | 5 | 11-07-2005 11:34 PM |
| Memory Problem - I think... | Unregistered | C Programming | 4 | 10-24-2001 12:14 PM |