stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r383739 - in /incubator/stdcxx/trunk/examples/manual: b_search.cpp binary_search.cpp out/b_search.out out/binary_search.out
Date Tue, 07 Mar 2006 01:19:00 GMT
Author: sebor
Date: Mon Mar  6 17:18:58 2006
New Revision: 383739

URL: http://svn.apache.org/viewcvs?rev=383739&view=rev
Log:
2006-03-06  Martin Sebor  <sebor@roguewave.com>

	* b_search.cpp: Uncomplicated tricky expression to deconfuse
	the XLC++ 8.0 optimizitor. Introduced convenience typedefs
	for better readability. Renamed...
	* binary_search.cpp: ...to this.
	* b_search.out: Renamed...
	* binary_search.out: ...to this.

Added:
    incubator/stdcxx/trunk/examples/manual/binary_search.cpp
      - copied, changed from r383661, incubator/stdcxx/trunk/examples/manual/b_search.cpp
    incubator/stdcxx/trunk/examples/manual/out/binary_search.out   (props changed)
      - copied unchanged from r383661, incubator/stdcxx/trunk/examples/manual/out/b_search.out
Removed:
    incubator/stdcxx/trunk/examples/manual/b_search.cpp
    incubator/stdcxx/trunk/examples/manual/out/b_search.out

Copied: incubator/stdcxx/trunk/examples/manual/binary_search.cpp (from r383661, incubator/stdcxx/trunk/examples/manual/b_search.cpp)
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/examples/manual/binary_search.cpp?p2=incubator/stdcxx/trunk/examples/manual/binary_search.cpp&p1=incubator/stdcxx/trunk/examples/manual/b_search.cpp&r1=383661&r2=383739&rev=383739&view=diff
==============================================================================
--- incubator/stdcxx/trunk/examples/manual/b_search.cpp (original)
+++ incubator/stdcxx/trunk/examples/manual/binary_search.cpp Mon Mar  6 17:18:58 2006
@@ -1,29 +1,35 @@
 /**************************************************************************
  *
- * b_search.cpp - Example program of binary search. 
+ * binary_search.cpp - Example program of binary search. 
  *
- * $Id: //stdlib/dev/examples/stdlib/manual/b_search.cpp#12 $
+ * $Id$
  *
  ***************************************************************************
  *
- * Copyright (c) 1994-2005 Quovadx,  Inc., acting through its  Rogue Wave
- * Software division. Licensed under the Apache License, Version 2.0 (the
- * "License");  you may  not use this file except  in compliance with the
- * License.    You    may   obtain   a   copy   of    the   License    at
- * http://www.apache.org/licenses/LICENSE-2.0.    Unless   required    by
- * applicable law  or agreed to  in writing,  software  distributed under
- * the License is distributed on an "AS IS" BASIS,  WITHOUT WARRANTIES OR
- * CONDITIONS OF  ANY KIND, either  express or implied.  See  the License
- * for the specific language governing permissions  and limitations under
- * the License.
+ * Copyright 2005-2006 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * Copyright 1994-2006 Rogue Wave Software.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  * 
  **************************************************************************/
 
 #include <algorithm>    // for binary_search(), copy(), sort()
 #include <deque>        // for deque
 #include <functional>   // for less
-#include <iostream>     // for cout, endl
-#include <iterator>     // for ostream_iterator
+#include <iostream>     // for cout
+#include <iterator>     // for ostream_iterator, char_traits
 
 #include <examples.h>
 
@@ -31,32 +37,36 @@
 int main ()
 {
     // Typedefs for convenience.
-    typedef std::deque<short, std::allocator<short> > Deque;
-
-    typedef std::ostream_iterator<Deque::value_type,
-                                  char,
-                                  std::char_traits<char> > os_iter;
+    typedef short                                      Value;
+    typedef std::deque<Value, std::allocator<Value> >  Deque;
+    typedef std::char_traits<char>                     Traits;
+    typedef std::ostream_iterator<Value, char, Traits> Iterator;
 
-    const Deque::value_type arr[] = { 0, 1, 2, 2, 3, 4, 2, 2, 6, 7 };
+    const Value arr[] = { 0, 1, 2, 2, 3, 4, 2, 2, 6, 7 };
 
     // Populate and sort the container.
     Deque d (arr + 0, arr + sizeof arr / sizeof *arr);
     std::sort (d.begin (), d.end ());
 
+    // Arbitrary values to search for.
+    const Value val_1 = 3;
+    const Value val_2 = 11;
+
     // Try binary_search variants.
-    bool b1 = std::binary_search (d.begin (), d.end (), 3);
-    bool b2 = std::binary_search (d.begin (), d.end (), 11,
-                                  std::less<int>());
+    const bool found_1 = std::binary_search (d.begin (), d.end (), val_1);
+    const bool found_2 = std::binary_search (d.begin (), d.end (), val_2,
+                                             std::less<Value>());
 
-    // Output results.
+    // Output the sorted sequence.
     std::cout << "Container contents: ";
-    std::copy (d.begin (), d.end (), os_iter (std::cout, " "));
+    std::copy (d.begin (), d.end (), Iterator (std::cout, " "));
 
-    std::cout << "\nThe number 3 was " 
-              << ("NOT found" + b1 * 4);
+    // Output the results of the algorithms.
+    std::cout << "\nThe number " << val_1 << " was "
+              << (found_1 ? "" : "NOT ") <<  "found";
 
-    std::cout << "\nThe number 11 was "
-              << ("NOT found" + b2 * 4) << std::endl;
+    std::cout << "\nThe number " << val_2 << " was "
+              << (found_2 ? "" : "NOT ") << "found\n";
 
     return 0;
 }

Propchange: incubator/stdcxx/trunk/examples/manual/out/binary_search.out
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/stdcxx/trunk/examples/manual/out/binary_search.out
------------------------------------------------------------------------------
    svn:keywords = Id



Mime
View raw message