How can I transform source range to destination range that is thesame as source?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Lambda

    How can I transform source range to destination range that is thesame as source?

    I'd like to change all the character in a array to lower case.
    I find transform() is convenient.

    Because the array is large, I don't want to define another array. I
    tried:

    transform(buffe r, buffer + size, buffer, tolower);

    From the output, I find it works.
    But when I compile it with Visual C++,
    I find a warning that says 'Function call with parameters that may be
    unsafe'.

    I shouldn't use transform that way?
    I must define another array to store the result or
    do it without transform?
  • Sam

    #2
    Re: How can I transform source range to destination range that isthe same as source?

    Lambda writes:
    I'd like to change all the character in a array to lower case.
    I find transform() is convenient.
    >
    Because the array is large, I don't want to define another array. I
    tried:
    >
    transform(buffe r, buffer + size, buffer, tolower);
    >
    From the output, I find it works.
    But when I compile it with Visual C++,
    I find a warning that says 'Function call with parameters that may be
    unsafe'.
    >
    I shouldn't use transform that way?
    I see nothing wrong with this. The only thing that's wrong here is your
    choice of using Microsoft's technology for learning C++. It's a known cause
    of brain rot.
    I must define another array to store the result or
    do it without transform?
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.9 (GNU/Linux)

    iEYEABECAAYFAkh 913oACgkQx9p3GY HlUOLHIACeIjNkT D4r38xxOaJLMLfH azVl
    IyAAn3n7voOP+ED 3mQTL0ZoMDUoc5/p7
    =QuXV
    -----END PGP SIGNATURE-----

    Comment

    • James Kanze

      #3
      Re: How can I transform source range to destination range that is thesame as source?

      On Jul 16, 12:43 pm, Lambda <stephenh...@gm ail.comwrote:
      I'd like to change all the character in a array to lower case.
      I find transform() is convenient.
      Because the array is large, I don't want to define another array. I
      tried:
      transform(buffe r, buffer + size, buffer, tolower);
      From the output, I find it works.
      Depending on the includes, it's likely to not even compile. And
      if it does, the results have undefined behavior.
      But when I compile it with Visual C++,
      I find a warning that says 'Function call with parameters that
      may be unsafe'.
      Which one?
      I shouldn't use transform that way?
      No.
      I must define another array to store the result or
      do it without transform?
      No, but you do have to provide a functional object that is
      unambiguous and that works correctly on the data type. You also
      should be using std::vector instead of whatever; it would make
      life a lot easier.

      And finally, of course, you should be aware that upper to lower
      case is not necessarily a one to one mapping, and that it is
      very locale dependent.

      --
      James Kanze (GABI Software) email:james.kan ze@gmail.com
      Conseils en informatique orientée objet/
      Beratung in objektorientier ter Datenverarbeitu ng
      9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

      Comment

      Working...